Address review on v1 sector extension tool
This commit is contained in:
parent
01bf3a89f4
commit
72c410cd8f
@ -50,6 +50,7 @@ var FaultDeclarationCutoff = miner0.FaultDeclarationCutoff
|
|||||||
const MinSectorExpiration = miner0.MinSectorExpiration
|
const MinSectorExpiration = miner0.MinSectorExpiration
|
||||||
|
|
||||||
// Not used / checked in v0
|
// Not used / checked in v0
|
||||||
|
// TODO: Abstract over network versions
|
||||||
var DeclarationsMax = miner2.DeclarationsMax
|
var DeclarationsMax = miner2.DeclarationsMax
|
||||||
var AddressedSectorsMax = miner2.AddressedSectorsMax
|
var AddressedSectorsMax = miner2.AddressedSectorsMax
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ func DealProviderCollateralBounds(
|
|||||||
case actors.Version3:
|
case actors.Version3:
|
||||||
return market3.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
return market3.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
||||||
default:
|
default:
|
||||||
panic("unsupported network version")
|
panic("unsupported actors version")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,3 +191,38 @@ func GetDefaultSectorSize() abi.SectorSize {
|
|||||||
|
|
||||||
return szs[0]
|
return szs[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version) abi.ChainEpoch {
|
||||||
|
if nwVer <= network.Version10 {
|
||||||
|
return builtin3.SealProofPoliciesV0[proof].SectorMaxLifetime
|
||||||
|
}
|
||||||
|
|
||||||
|
return builtin3.SealProofPoliciesV11[proof].SectorMaxLifetime
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAddressedSectorsMax(nwVer network.Version) int {
|
||||||
|
switch actors.VersionForNetwork(nwVer) {
|
||||||
|
case actors.Version0:
|
||||||
|
return miner0.AddressedSectorsMax
|
||||||
|
case actors.Version2:
|
||||||
|
return miner2.AddressedSectorsMax
|
||||||
|
case actors.Version3:
|
||||||
|
return miner3.AddressedSectorsMax
|
||||||
|
default:
|
||||||
|
panic("unsupported network version")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDeclarationsMax(nwVer network.Version) int {
|
||||||
|
switch actors.VersionForNetwork(nwVer) {
|
||||||
|
case actors.Version0:
|
||||||
|
// TODO: Should we instead panic here since the concept doesn't exist yet?
|
||||||
|
return miner0.AddressedPartitionsMax
|
||||||
|
case actors.Version2:
|
||||||
|
return miner2.DeclarationsMax
|
||||||
|
case actors.Version3:
|
||||||
|
return miner3.DeclarationsMax
|
||||||
|
default:
|
||||||
|
panic("unsupported network version")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,10 +8,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
|
||||||
|
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@ -433,6 +429,17 @@ var sectorsExtendCmd = &cli.Command{
|
|||||||
Usage: "renews all v1 sectors up to the maximum possible lifetime",
|
Usage: "renews all v1 sectors up to the maximum possible lifetime",
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
|
&cli.Int64Flag{
|
||||||
|
Name: "tolerance",
|
||||||
|
Value: 20160,
|
||||||
|
Usage: "when extending v1 sectors, don't try to extend sectors by fewer than this number of epochs",
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
|
&cli.Int64Flag{
|
||||||
|
Name: "expiration-cutoff",
|
||||||
|
Usage: "when extending v1 sectors, skip sectors whose current expiration is more than <cutoff> epochs from now (infinity if unspecified)",
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
&cli.StringFlag{},
|
&cli.StringFlag{},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
@ -453,15 +460,27 @@ var sectorsExtendCmd = &cli.Command{
|
|||||||
var params []miner3.ExtendSectorExpirationParams
|
var params []miner3.ExtendSectorExpirationParams
|
||||||
|
|
||||||
if cctx.Bool("v1-sectors") {
|
if cctx.Bool("v1-sectors") {
|
||||||
|
|
||||||
|
head, err := api.ChainHead(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
nv, err := api.StateNetworkVersion(ctx, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
extensions := map[miner.SectorLocation]map[abi.ChainEpoch][]uint64{}
|
extensions := map[miner.SectorLocation]map[abi.ChainEpoch][]uint64{}
|
||||||
// are given durations within a week?
|
|
||||||
closeEnough := func(a, b abi.ChainEpoch) bool {
|
// are given durations within tolerance epochs
|
||||||
|
withinTolerance := func(a, b abi.ChainEpoch) bool {
|
||||||
diff := a - b
|
diff := a - b
|
||||||
if diff < 0 {
|
if diff < 0 {
|
||||||
diff = b - a
|
diff = b - a
|
||||||
}
|
}
|
||||||
|
|
||||||
return diff <= 7*builtin.EpochsInDay
|
return diff <= abi.ChainEpoch(cctx.Int64("tolerance"))
|
||||||
}
|
}
|
||||||
|
|
||||||
sis, err := api.StateMinerActiveSectors(ctx, maddr, types.EmptyTSK)
|
sis, err := api.StateMinerActiveSectors(ctx, maddr, types.EmptyTSK)
|
||||||
@ -470,53 +489,63 @@ var sectorsExtendCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, si := range sis {
|
for _, si := range sis {
|
||||||
if si.SealProof < abi.RegisteredSealProof_StackedDrg2KiBV1_1 {
|
if si.SealProof >= abi.RegisteredSealProof_StackedDrg2KiBV1_1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
ml := builtin3.SealProofPoliciesV11[si.SealProof].SectorMaxLifetime
|
if cctx.IsSet("expiration-cutoff") {
|
||||||
// if the sector's missing less than a week of its maximum possible lifetime, don't bother extending it
|
if si.Expiration > (head.Height() + abi.ChainEpoch(cctx.Int64("expiration-cutoff"))) {
|
||||||
if closeEnough(si.Expiration-si.Activation, ml) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newExp := ml - (miner3.WPoStProvingPeriod * 2) + si.Activation
|
ml := policy.GetSectorMaxLifetime(si.SealProof, nv)
|
||||||
p, err := api.StateSectorPartition(ctx, maddr, si.SectorNumber, types.EmptyTSK)
|
// if the sector's missing less than "tolerance" of its maximum possible lifetime, don't bother extending it
|
||||||
if err != nil {
|
if withinTolerance(si.Expiration-si.Activation, ml) {
|
||||||
return xerrors.Errorf("getting sector location for sector %d: %w", si.SectorNumber, err)
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the new expiration to 48 hours less than the theoretical maximum lifetime
|
||||||
|
newExp := ml - (miner3.WPoStProvingPeriod * 2) + si.Activation
|
||||||
|
p, err := api.StateSectorPartition(ctx, maddr, si.SectorNumber, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("getting sector location for sector %d: %w", si.SectorNumber, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if p == nil {
|
||||||
|
return xerrors.Errorf("sector %d not found in any partition", si.SectorNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
es, found := extensions[*p]
|
||||||
|
if !found {
|
||||||
|
ne := make(map[abi.ChainEpoch][]uint64)
|
||||||
|
ne[newExp] = []uint64{uint64(si.SectorNumber)}
|
||||||
|
extensions[*p] = ne
|
||||||
|
} else {
|
||||||
|
added := false
|
||||||
|
for exp := range es {
|
||||||
|
if withinTolerance(exp, newExp) {
|
||||||
|
es[exp] = append(es[exp], uint64(si.SectorNumber))
|
||||||
|
added = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if p == nil {
|
if !added {
|
||||||
return xerrors.Errorf("sector %d not found in any partition", si.SectorNumber)
|
es[newExp] = []uint64{uint64(si.SectorNumber)}
|
||||||
}
|
|
||||||
|
|
||||||
es, found := extensions[*p]
|
|
||||||
if !found {
|
|
||||||
ne := make(map[abi.ChainEpoch][]uint64)
|
|
||||||
ne[newExp] = []uint64{uint64(si.SectorNumber)}
|
|
||||||
extensions[*p] = ne
|
|
||||||
} else {
|
|
||||||
added := false
|
|
||||||
for exp := range es {
|
|
||||||
if closeEnough(exp, newExp) {
|
|
||||||
es[exp] = append(es[exp], uint64(si.SectorNumber))
|
|
||||||
added = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !added {
|
|
||||||
es[newExp] = []uint64{uint64(si.SectorNumber)}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p := &miner3.ExtendSectorExpirationParams{}
|
|
||||||
|
p := miner3.ExtendSectorExpirationParams{}
|
||||||
scount := 0
|
scount := 0
|
||||||
|
|
||||||
for l, exts := range extensions {
|
for l, exts := range extensions {
|
||||||
for newExp, numbers := range exts {
|
for newExp, numbers := range exts {
|
||||||
scount += len(numbers)
|
scount += len(numbers)
|
||||||
if scount > miner.AddressedSectorsMax || len(p.Extensions) == miner3.DeclarationsMax {
|
if scount > policy.GetAddressedSectorsMax(nv) || len(p.Extensions) == policy.GetDeclarationsMax(nv) {
|
||||||
params = append(params, *p)
|
params = append(params, p)
|
||||||
p = &miner3.ExtendSectorExpirationParams{}
|
p = miner3.ExtendSectorExpirationParams{}
|
||||||
scount = len(numbers)
|
scount = len(numbers)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,7 +557,11 @@ var sectorsExtendCmd = &cli.Command{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
params = append(params, *p)
|
|
||||||
|
// if we have any sectors, then one last append is needed here
|
||||||
|
if scount != 0 {
|
||||||
|
params = append(params, p)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if !cctx.Args().Present() || !cctx.IsSet("new-expiration") {
|
if !cctx.Args().Present() || !cctx.IsSet("new-expiration") {
|
||||||
@ -554,9 +587,10 @@ var sectorsExtendCmd = &cli.Command{
|
|||||||
sectors[*p] = append(sectors[*p], id)
|
sectors[*p] = append(sectors[*p], id)
|
||||||
}
|
}
|
||||||
|
|
||||||
p := &miner3.ExtendSectorExpirationParams{}
|
p := miner3.ExtendSectorExpirationParams{}
|
||||||
for l, numbers := range sectors {
|
for l, numbers := range sectors {
|
||||||
|
|
||||||
|
// TODO: Dedup with above loop
|
||||||
p.Extensions = append(p.Extensions, miner3.ExpirationExtension{
|
p.Extensions = append(p.Extensions, miner3.ExpirationExtension{
|
||||||
Deadline: l.Deadline,
|
Deadline: l.Deadline,
|
||||||
Partition: l.Partition,
|
Partition: l.Partition,
|
||||||
@ -565,7 +599,12 @@ var sectorsExtendCmd = &cli.Command{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
params = append(params, *p)
|
params = append(params, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(params) == 0 {
|
||||||
|
fmt.Println("nothing to extend")
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
||||||
|
Loading…
Reference in New Issue
Block a user