Skip to content

Commit

Permalink
refactor: GetMaxSectorExpirationExtension depends on network version
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Sep 23, 2023
1 parent 9b40880 commit 9e431d9
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 19 deletions.
49 changes: 47 additions & 2 deletions chain/actors/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,53 @@ func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch {
return ChainFinality
}

func GetMaxSectorExpirationExtension() abi.ChainEpoch {
return miner12.MaxSectorExpirationExtension
func GetMaxSectorExpirationExtension(nv network.Version) (abi.ChainEpoch, error) {
v, err := actorstypes.VersionForNetwork(nv)
if err != nil {
return 0, xerrors.Errorf("failed to get actors version: %w", err)
}
switch v {

case actorstypes.Version0:
return miner0.MaxSectorExpirationExtension, nil

case actorstypes.Version2:
return miner2.MaxSectorExpirationExtension, nil

case actorstypes.Version3:
return miner3.MaxSectorExpirationExtension, nil

case actorstypes.Version4:
return miner4.MaxSectorExpirationExtension, nil

case actorstypes.Version5:
return miner5.MaxSectorExpirationExtension, nil

case actorstypes.Version6:
return miner6.MaxSectorExpirationExtension, nil

case actorstypes.Version7:
return miner7.MaxSectorExpirationExtension, nil

case actorstypes.Version8:
return miner8.MaxSectorExpirationExtension, nil

case actorstypes.Version9:
return miner9.MaxSectorExpirationExtension, nil

case actorstypes.Version10:
return miner10.MaxSectorExpirationExtension, nil

case actorstypes.Version11:
return miner11.MaxSectorExpirationExtension, nil

case actorstypes.Version12:
return miner12.MaxSectorExpirationExtension, nil

default:
return 0, xerrors.Errorf("unsupported network version")
}

}

func GetMinSectorExpiration() abi.ChainEpoch {
Expand Down
16 changes: 14 additions & 2 deletions chain/actors/policy/policy.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,20 @@ func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch {
return ChainFinality
}

func GetMaxSectorExpirationExtension() abi.ChainEpoch {
return miner{{.latestVersion}}.MaxSectorExpirationExtension
func GetMaxSectorExpirationExtension(nv network.Version) (abi.ChainEpoch, error) {
v, err := actorstypes.VersionForNetwork(nv)
if err != nil {
return 0, xerrors.Errorf("failed to get actors version: %w", err)
}
switch v {
{{range .versions}}
case actorstypes.Version{{.}}:
return miner{{.}}.MaxSectorExpirationExtension, nil
{{end}}
default:
return 0, xerrors.Errorf("unsupported network version")
}

}

func GetMinSectorExpiration() abi.ChainEpoch {
Expand Down
6 changes: 5 additions & 1 deletion chain/gen/genesis/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
sectorWeight []abi.StoragePower
}, len(miners))

maxPeriods := policy.GetMaxSectorExpirationExtension() / minertypes.WPoStProvingPeriod
maxLifetime, err := policy.GetMaxSectorExpirationExtension(nv)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to get max extension: %w", err)
}
maxPeriods := maxLifetime / minertypes.WPoStProvingPeriod
rawPow, qaPow := big.NewInt(0), big.NewInt(0)
for i, m := range miners {
// Create miner through power actor
Expand Down
21 changes: 18 additions & 3 deletions cmd/lotus-miner/sectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,12 @@ var sectorsCheckExpireCmd = &cli.Command{

for _, sector := range sectors {
MaxExpiration := sector.Activation + policy.GetSectorMaxLifetime(sector.SealProof, nv)
MaxExtendNow := currEpoch + policy.GetMaxSectorExpirationExtension()
maxExtension, err := policy.GetMaxSectorExpirationExtension(nv)
if err != nil {
return xerrors.Errorf("failed to get max extension: %w", err)
}

MaxExtendNow := currEpoch + maxExtension

if MaxExtendNow > MaxExpiration {
MaxExtendNow = MaxExpiration
Expand Down Expand Up @@ -1185,7 +1190,12 @@ var sectorsExtendCmd = &cli.Command{
newExp = abi.ChainEpoch(cctx.Int64("new-expiration"))
}

maxExtendNow := currEpoch + policy.GetMaxSectorExpirationExtension()
maxExtension, err := policy.GetMaxSectorExpirationExtension(nv)
if err != nil {
return xerrors.Errorf("failed to get max extension: %w", err)
}

maxExtendNow := currEpoch + maxExtension
if newExp > maxExtendNow {
newExp = maxExtendNow
}
Expand Down Expand Up @@ -1755,7 +1765,12 @@ var sectorsCapacityCollateralCmd = &cli.Command{
return err
}

pci.Expiration = policy.GetMaxSectorExpirationExtension() + h.Height()
maxExtension, err := policy.GetMaxSectorExpirationExtension(nv)
if err != nil {
return xerrors.Errorf("failed to get max extension: %w", err)
}

pci.Expiration = maxExtension + h.Height()
}

pc, err := nApi.StateMinerInitialPledgeCollateral(ctx, maddr, pci, types.EmptyTSK)
Expand Down
7 changes: 6 additions & 1 deletion cmd/lotus-sim/simulation/stages/precommit_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ func (stage *PreCommitStage) packMiner(
return 0, false, err
}

expiration := epoch + policy.GetMaxSectorExpirationExtension()
maxExtension, err := policy.GetMaxSectorExpirationExtension(nv)
if err != nil {
return 0, false, xerrors.Errorf("failed to get max extension: %w", err)
}

expiration := epoch + maxExtension
infos := make([]minertypes.PreCommitSectorParams, len(sectorNos))
for i, sno := range sectorNos {
infos[i] = minertypes.PreCommitSectorParams{
Expand Down
5 changes: 4 additions & 1 deletion node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/network"
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"

"github.com/filecoin-project/lotus/chain/actors/builtin"
Expand Down Expand Up @@ -122,6 +123,8 @@ func DefaultFullNode() *FullNode {
}

func DefaultStorageMiner() *StorageMiner {
// TODO: Should we increase this to nv21, which would push it to 3.5 years?
maxSectorExtentsion, _ := policy.GetMaxSectorExpirationExtension(network.Version20)
cfg := &StorageMiner{
Common: defCommon(),

Expand All @@ -143,7 +146,7 @@ func DefaultStorageMiner() *StorageMiner {
// XXX snap deals wait deals slack if first
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 * uint64(policy.GetMaxSectorExpirationExtension()) * uint64(time.Second)),
CommittedCapacitySectorLifetime: Duration(builtin.EpochDurationSeconds * uint64(maxSectorExtentsion) * uint64(time.Second)),

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
Expand Down
24 changes: 17 additions & 7 deletions storage/pipeline/precommit_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...api.SectorP
}

if end == nil {
nv, err := p.api.StateNetworkVersion(ctx, types.EmptyTSK)
if err != nil {
return 0, xerrors.Errorf("failed to get network version: %w", err)
}

// no deal pieces, get expiration for committed capacity sector
expirationDuration, err := p.getCCSectorLifetime()
expirationDuration, err := p.getCCSectorLifetime(nv)
if err != nil {
return 0, err
return 0, xerrors.Errorf("failed to get cc sector lifetime: %w", err)
}

tmp := ts.Height() + expirationDuration
Expand All @@ -105,25 +110,30 @@ func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...api.SectorP
return *end, nil
}

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

maxCommitment, err := policy.GetMaxSectorExpirationExtension(nv)
if err != nil {
return 0, xerrors.Errorf("failed to get max extension: %w", err)
}

var ccLifetimeEpochs = abi.ChainEpoch(uint64(c.CommittedCapacitySectorLifetime.Seconds()) / builtin.EpochDurationSeconds)
// if zero value in config, assume default sector extension
if ccLifetimeEpochs == 0 {
ccLifetimeEpochs = policy.GetMaxSectorExpirationExtension()
ccLifetimeEpochs = maxCommitment
}

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

return ccLifetimeEpochs - p.provingBuffer, nil
Expand Down
4 changes: 3 additions & 1 deletion storage/pipeline/precommit_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ func TestBasicPolicyEmptySector(t *testing.T) {
require.NoError(t, err)

// as set when there are no deal pieces
expected := h + policy.GetMaxSectorExpirationExtension() - pBuffer
maxExtension, err := policy.GetMaxSectorExpirationExtension(build.TestNetworkVersion)
assert.NoError(t, err)
expected := h + maxExtension - pBuffer
assert.Equal(t, int(expected), int(exp))
}

Expand Down
7 changes: 6 additions & 1 deletion storage/pipeline/states_sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,12 @@ func (m *Sealing) preCommitInfo(ctx statemachine.Context, sector SectorInfo) (*m
}

// Assume: both precommit msg & commit msg land on chain as early as possible
maxExpiration := ts.Height() + policy.GetPreCommitChallengeDelay() + policy.GetMaxSectorExpirationExtension()
maxExtension, err := policy.GetMaxSectorExpirationExtension(nv)
if err != nil {
return nil, big.Zero(), types.EmptyTSK, ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("failed to get max extension: %w", err)})
}

maxExpiration := ts.Height() + policy.GetPreCommitChallengeDelay() + maxExtension
if expiration > maxExpiration {
expiration = maxExpiration
}
Expand Down

0 comments on commit 9e431d9

Please sign in to comment.