2020-09-23 19:24:51 +00:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
2020-10-08 01:09:33 +00:00
|
|
|
"sort"
|
|
|
|
|
2020-09-23 19:24:51 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-09-30 20:30:24 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2020-09-29 00:28:16 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2021-01-21 18:44:13 +00:00
|
|
|
|
2021-04-30 18:35:01 +00:00
|
|
|
/* TEMPLATE START
|
|
|
|
{{range .versions}}
|
|
|
|
market{{.v}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/market"
|
|
|
|
miner{{.v}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/miner"
|
|
|
|
power{{.v}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/power"
|
|
|
|
verifreg{{.v}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/verifreg"
|
|
|
|
{{end}}
|
|
|
|
* GENERATED WITH make gen */
|
2020-09-30 20:30:24 +00:00
|
|
|
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
2020-09-23 19:24:51 +00:00
|
|
|
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
|
|
|
power0 "github.com/filecoin-project/specs-actors/actors/builtin/power"
|
|
|
|
verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
|
2021-01-21 18:44:13 +00:00
|
|
|
|
2020-09-29 00:28:16 +00:00
|
|
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
2020-09-30 20:30:24 +00:00
|
|
|
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
|
2020-09-29 00:28:16 +00:00
|
|
|
miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
|
|
|
|
verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg"
|
2021-01-21 18:44:13 +00:00
|
|
|
|
|
|
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
|
|
|
market3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/market"
|
|
|
|
miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner"
|
|
|
|
verifreg3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/verifreg"
|
2021-04-23 12:29:46 +00:00
|
|
|
|
|
|
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
|
|
|
market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market"
|
|
|
|
miner4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner"
|
|
|
|
paych4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/paych"
|
|
|
|
verifreg4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg"
|
2021-04-30 18:35:01 +00:00
|
|
|
/* GENERATED END */)
|
2020-09-29 00:28:16 +00:00
|
|
|
|
|
|
|
const (
|
2021-04-27 06:13:49 +00:00
|
|
|
ChainFinality = miner4.ChainFinality
|
2021-02-04 08:42:02 +00:00
|
|
|
SealRandomnessLookback = ChainFinality
|
2021-04-27 06:13:49 +00:00
|
|
|
PaychSettleDelay = paych4.SettleDelay
|
|
|
|
MaxPreCommitRandomnessLookback = builtin4.EpochsInDay + SealRandomnessLookback
|
2020-09-23 19:24:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetSupportedProofTypes sets supported proof types, across all actor versions.
|
|
|
|
// This should only be used for testing.
|
|
|
|
func SetSupportedProofTypes(types ...abi.RegisteredSealProof) {
|
2020-11-07 05:05:16 +00:00
|
|
|
miner0.SupportedProofTypes = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
|
|
|
miner2.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
2020-11-20 09:24:52 +00:00
|
|
|
miner2.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2)
|
2020-11-07 05:05:16 +00:00
|
|
|
miner2.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
|
|
|
|
2021-01-21 18:44:13 +00:00
|
|
|
miner3.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
2021-01-22 16:30:58 +00:00
|
|
|
miner3.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2)
|
2021-01-21 18:44:13 +00:00
|
|
|
miner3.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
miner4.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
|
|
|
miner4.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2)
|
|
|
|
miner4.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
|
|
|
|
2020-11-07 05:05:16 +00:00
|
|
|
AddSupportedProofTypes(types...)
|
2020-09-23 19:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddSupportedProofTypes sets supported proof types, across all actor versions.
|
|
|
|
// This should only be used for testing.
|
|
|
|
func AddSupportedProofTypes(types ...abi.RegisteredSealProof) {
|
|
|
|
for _, t := range types {
|
2020-11-07 05:05:16 +00:00
|
|
|
if t >= abi.RegisteredSealProof_StackedDrg2KiBV1_1 {
|
|
|
|
panic("must specify v1 proof types only")
|
|
|
|
}
|
2020-09-25 21:33:25 +00:00
|
|
|
// Set for all miner versions.
|
|
|
|
miner0.SupportedProofTypes[t] = struct{}{}
|
2020-11-07 05:05:16 +00:00
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
miner2.PreCommitSealProofTypesV0[t] = struct{}{}
|
2020-11-08 04:05:52 +00:00
|
|
|
miner2.PreCommitSealProofTypesV7[t] = struct{}{}
|
2020-11-07 05:05:16 +00:00
|
|
|
miner2.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
|
|
|
miner2.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
2021-01-21 18:44:13 +00:00
|
|
|
|
|
|
|
miner3.PreCommitSealProofTypesV0[t] = struct{}{}
|
|
|
|
miner3.PreCommitSealProofTypesV7[t] = struct{}{}
|
|
|
|
miner3.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
|
|
|
miner3.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
2021-04-23 12:29:46 +00:00
|
|
|
|
|
|
|
miner4.PreCommitSealProofTypesV0[t] = struct{}{}
|
|
|
|
miner4.PreCommitSealProofTypesV7[t] = struct{}{}
|
|
|
|
miner4.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
|
|
|
miner4.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
2020-09-23 19:24:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetPreCommitChallengeDelay sets the pre-commit challenge delay across all
|
|
|
|
// actors versions. Use for testing.
|
|
|
|
func SetPreCommitChallengeDelay(delay abi.ChainEpoch) {
|
|
|
|
// Set for all miner versions.
|
|
|
|
miner0.PreCommitChallengeDelay = delay
|
2020-09-29 00:28:16 +00:00
|
|
|
miner2.PreCommitChallengeDelay = delay
|
2021-01-21 18:44:13 +00:00
|
|
|
miner3.PreCommitChallengeDelay = delay
|
2021-04-23 12:29:46 +00:00
|
|
|
miner4.PreCommitChallengeDelay = delay
|
2020-09-23 19:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay.
|
|
|
|
func GetPreCommitChallengeDelay() abi.ChainEpoch {
|
|
|
|
return miner0.PreCommitChallengeDelay
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetConsensusMinerMinPower sets the minimum power of an individual miner must
|
|
|
|
// meet for leader election, across all actor versions. This should only be used
|
|
|
|
// for testing.
|
|
|
|
func SetConsensusMinerMinPower(p abi.StoragePower) {
|
|
|
|
power0.ConsensusMinerMinPower = p
|
2020-09-29 00:28:16 +00:00
|
|
|
for _, policy := range builtin2.SealProofPolicies {
|
|
|
|
policy.ConsensusMinerMinPower = p
|
|
|
|
}
|
2021-01-21 18:44:13 +00:00
|
|
|
|
|
|
|
for _, policy := range builtin3.PoStProofPolicies {
|
|
|
|
policy.ConsensusMinerMinPower = p
|
|
|
|
}
|
2021-04-23 12:29:46 +00:00
|
|
|
|
|
|
|
for _, policy := range builtin4.PoStProofPolicies {
|
|
|
|
policy.ConsensusMinerMinPower = p
|
|
|
|
}
|
2020-09-23 19:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetMinVerifiedDealSize sets the minimum size of a verified deal. This should
|
|
|
|
// only be used for testing.
|
|
|
|
func SetMinVerifiedDealSize(size abi.StoragePower) {
|
|
|
|
verifreg0.MinVerifiedDealSize = size
|
2020-09-29 00:28:16 +00:00
|
|
|
verifreg2.MinVerifiedDealSize = size
|
2021-01-21 18:44:13 +00:00
|
|
|
verifreg3.MinVerifiedDealSize = size
|
2021-04-23 12:29:46 +00:00
|
|
|
verifreg4.MinVerifiedDealSize = size
|
2020-09-29 00:28:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) abi.ChainEpoch {
|
|
|
|
switch ver {
|
|
|
|
case actors.Version0:
|
|
|
|
return miner0.MaxSealDuration[t]
|
|
|
|
case actors.Version2:
|
|
|
|
return miner2.MaxProveCommitDuration[t]
|
2021-01-21 18:44:13 +00:00
|
|
|
case actors.Version3:
|
|
|
|
return miner3.MaxProveCommitDuration[t]
|
2021-04-23 12:29:46 +00:00
|
|
|
case actors.Version4:
|
|
|
|
return miner4.MaxProveCommitDuration[t]
|
2020-09-29 00:28:16 +00:00
|
|
|
default:
|
|
|
|
panic("unsupported actors version")
|
|
|
|
}
|
2020-09-23 19:24:51 +00:00
|
|
|
}
|
2020-09-30 20:30:24 +00:00
|
|
|
|
|
|
|
func DealProviderCollateralBounds(
|
|
|
|
size abi.PaddedPieceSize, verified bool,
|
|
|
|
rawBytePower, qaPower, baselinePower abi.StoragePower,
|
|
|
|
circulatingFil abi.TokenAmount, nwVer network.Version,
|
|
|
|
) (min, max abi.TokenAmount) {
|
|
|
|
switch actors.VersionForNetwork(nwVer) {
|
|
|
|
case actors.Version0:
|
|
|
|
return market0.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer)
|
|
|
|
case actors.Version2:
|
|
|
|
return market2.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
2021-01-21 18:44:13 +00:00
|
|
|
case actors.Version3:
|
|
|
|
return market3.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
2021-04-23 12:29:46 +00:00
|
|
|
case actors.Version4:
|
|
|
|
return market4.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
2020-09-30 20:30:24 +00:00
|
|
|
default:
|
2021-04-04 02:02:06 +00:00
|
|
|
panic("unsupported actors version")
|
2020-09-30 20:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-05 21:28:47 +00:00
|
|
|
|
2020-12-30 08:02:53 +00:00
|
|
|
func DealDurationBounds(pieceSize abi.PaddedPieceSize) (min, max abi.ChainEpoch) {
|
|
|
|
return market2.DealDurationBounds(pieceSize)
|
|
|
|
}
|
|
|
|
|
2020-10-05 21:28:47 +00:00
|
|
|
// Sets the challenge window and scales the proving period to match (such that
|
|
|
|
// there are always 48 challenge windows in a proving period).
|
|
|
|
func SetWPoStChallengeWindow(period abi.ChainEpoch) {
|
|
|
|
miner0.WPoStChallengeWindow = period
|
|
|
|
miner0.WPoStProvingPeriod = period * abi.ChainEpoch(miner0.WPoStPeriodDeadlines)
|
|
|
|
|
|
|
|
miner2.WPoStChallengeWindow = period
|
|
|
|
miner2.WPoStProvingPeriod = period * abi.ChainEpoch(miner2.WPoStPeriodDeadlines)
|
2021-01-21 18:44:13 +00:00
|
|
|
|
|
|
|
miner3.WPoStChallengeWindow = period
|
|
|
|
miner3.WPoStProvingPeriod = period * abi.ChainEpoch(miner3.WPoStPeriodDeadlines)
|
2021-01-22 19:15:43 +00:00
|
|
|
// by default, this is 2x finality which is 30 periods.
|
|
|
|
// scale it if we're scaling the challenge period.
|
|
|
|
miner3.WPoStDisputeWindow = period * 30
|
2021-04-23 12:29:46 +00:00
|
|
|
|
|
|
|
miner4.WPoStChallengeWindow = period
|
|
|
|
miner4.WPoStProvingPeriod = period * abi.ChainEpoch(miner4.WPoStPeriodDeadlines)
|
|
|
|
miner4.WPoStDisputeWindow = period * 30 // see the miner3 comment
|
2020-10-05 21:28:47 +00:00
|
|
|
}
|
2020-10-06 09:26:25 +00:00
|
|
|
|
|
|
|
func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch {
|
|
|
|
if nwVer <= network.Version3 {
|
|
|
|
return 10
|
|
|
|
}
|
|
|
|
|
2021-05-05 20:54:01 +00:00
|
|
|
// NOTE: if this ever changes, adjust it in a (*Miner).mineOne() logline as well
|
2020-10-06 09:26:25 +00:00
|
|
|
return ChainFinality
|
|
|
|
}
|
2020-10-08 01:09:33 +00:00
|
|
|
|
|
|
|
func GetMaxSectorExpirationExtension() abi.ChainEpoch {
|
|
|
|
return miner0.MaxSectorExpirationExtension
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: we'll probably need to abstract over this better in the future.
|
|
|
|
func GetMaxPoStPartitions(p abi.RegisteredPoStProof) (int, error) {
|
2021-01-21 18:44:13 +00:00
|
|
|
sectorsPerPart, err := builtin3.PoStProofWindowPoStPartitionSectors(p)
|
2020-10-08 01:09:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2021-04-23 12:29:46 +00:00
|
|
|
return int(miner4.AddressedSectorsMax / sectorsPerPart), nil
|
2020-10-08 01:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetDefaultSectorSize() abi.SectorSize {
|
2020-11-08 04:05:52 +00:00
|
|
|
// supported sector sizes are the same across versions.
|
2021-04-23 12:29:46 +00:00
|
|
|
szs := make([]abi.SectorSize, 0, len(miner4.PreCommitSealProofTypesV8))
|
|
|
|
for spt := range miner4.PreCommitSealProofTypesV8 {
|
2020-10-08 01:09:33 +00:00
|
|
|
ss, err := spt.SectorSize()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
szs = append(szs, ss)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(szs, func(i, j int) bool {
|
|
|
|
return szs[i] < szs[j]
|
|
|
|
})
|
|
|
|
|
|
|
|
return szs[0]
|
|
|
|
}
|
2021-04-04 02:02:06 +00:00
|
|
|
|
|
|
|
func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version) abi.ChainEpoch {
|
|
|
|
if nwVer <= network.Version10 {
|
2021-04-23 12:29:46 +00:00
|
|
|
return builtin4.SealProofPoliciesV0[proof].SectorMaxLifetime
|
2021-04-04 02:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
return builtin4.SealProofPoliciesV11[proof].SectorMaxLifetime
|
2021-04-04 02:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2021-04-23 12:29:46 +00:00
|
|
|
case actors.Version4:
|
|
|
|
return miner4.AddressedSectorsMax
|
2021-04-04 02:02:06 +00:00
|
|
|
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
|
2021-04-23 12:29:46 +00:00
|
|
|
case actors.Version4:
|
|
|
|
return miner4.DeclarationsMax
|
2021-04-04 02:02:06 +00:00
|
|
|
default:
|
|
|
|
panic("unsupported network version")
|
|
|
|
}
|
|
|
|
}
|