2021-04-26 14:48:20 +00:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
|
2021-06-09 01:40:52 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2021-08-10 17:32:00 +00:00
|
|
|
"golang.org/x/xerrors"
|
2021-06-09 01:40:52 +00:00
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
|
|
|
|
{{range .versions}}
|
2022-04-20 21:34:28 +00:00
|
|
|
{{if (ge . 8)}}
|
|
|
|
builtin{{.}} "github.com/filecoin-project/go-state-types/builtin"
|
|
|
|
miner{{.}} "github.com/filecoin-project/go-state-types/builtin{{import .}}miner"
|
|
|
|
market{{.}} "github.com/filecoin-project/go-state-types/builtin{{import .}}market"
|
|
|
|
verifreg{{.}} "github.com/filecoin-project/go-state-types/builtin{{import .}}verifreg"
|
|
|
|
{{else}}
|
|
|
|
{{if (ge . 2)}}
|
|
|
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
|
|
|
|
{{end}}
|
|
|
|
market{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/market"
|
|
|
|
miner{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/miner"
|
|
|
|
verifreg{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/verifreg"
|
|
|
|
{{if (eq . 0)}}
|
|
|
|
power{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/power"
|
|
|
|
{{end}}
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
2022-04-20 21:34:28 +00:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
paych{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin{{import .latestVersion}}paych"
|
2021-04-26 14:48:20 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ChainFinality = miner{{.latestVersion}}.ChainFinality
|
|
|
|
SealRandomnessLookback = ChainFinality
|
|
|
|
PaychSettleDelay = paych{{.latestVersion}}.SettleDelay
|
|
|
|
MaxPreCommitRandomnessLookback = builtin{{.latestVersion}}.EpochsInDay + SealRandomnessLookback
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetSupportedProofTypes sets supported proof types, across all actor versions.
|
|
|
|
// This should only be used for testing.
|
|
|
|
func SetSupportedProofTypes(types ...abi.RegisteredSealProof) {
|
|
|
|
{{range .versions}}
|
2021-05-15 01:11:23 +00:00
|
|
|
{{if (eq . 0)}}
|
|
|
|
miner{{.}}.SupportedProofTypes = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
2021-05-31 19:38:34 +00:00
|
|
|
{{else if (le . 4)}}
|
2021-05-15 01:11:23 +00:00
|
|
|
miner{{.}}.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2)
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
2021-05-31 19:38:34 +00:00
|
|
|
{{else}}
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
AddSupportedProofTypes(types...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
if t >= abi.RegisteredSealProof_StackedDrg2KiBV1_1 {
|
|
|
|
panic("must specify v1 proof types only")
|
|
|
|
}
|
|
|
|
// Set for all miner versions.
|
|
|
|
|
|
|
|
{{range .versions}}
|
|
|
|
{{if (eq . 0)}}
|
|
|
|
miner{{.}}.SupportedProofTypes[t] = struct{}{}
|
2021-05-27 19:54:31 +00:00
|
|
|
{{else if (le . 4)}}
|
2021-04-26 14:48:20 +00:00
|
|
|
miner{{.}}.PreCommitSealProofTypesV0[t] = struct{}{}
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV7[t] = struct{}{}
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
2021-09-15 15:22:25 +00:00
|
|
|
{{else if (eq . 5)}}
|
2021-05-27 19:54:31 +00:00
|
|
|
miner{{.}}.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
2021-05-31 22:50:29 +00:00
|
|
|
wpp, err := t.RegisteredWindowPoStProof()
|
|
|
|
if err != nil {
|
|
|
|
// Fine to panic, this is a test-only method
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-09-15 15:22:25 +00:00
|
|
|
miner{{.}}.WindowPoStProofTypes[wpp] = struct{}{}
|
|
|
|
{{else}}
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
|
|
|
wpp, err = t.RegisteredWindowPoStProof()
|
|
|
|
if err != nil {
|
|
|
|
// Fine to panic, this is a test-only method
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-05-31 22:50:29 +00:00
|
|
|
miner{{.}}.WindowPoStProofTypes[wpp] = struct{}{}
|
2021-04-26 14:48:20 +00:00
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetPreCommitChallengeDelay sets the pre-commit challenge delay across all
|
|
|
|
// actors versions. Use for testing.
|
|
|
|
func SetPreCommitChallengeDelay(delay abi.ChainEpoch) {
|
|
|
|
// Set for all miner versions.
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
|
|
|
miner{{.}}.PreCommitChallengeDelay = delay
|
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay.
|
|
|
|
func GetPreCommitChallengeDelay() abi.ChainEpoch {
|
|
|
|
return miner{{.latestVersion}}.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) {
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
|
|
|
{{if (eq . 0)}}
|
|
|
|
power{{.}}.ConsensusMinerMinPower = p
|
|
|
|
{{else if (eq . 2)}}
|
|
|
|
for _, policy := range builtin{{.}}.SealProofPolicies {
|
|
|
|
policy.ConsensusMinerMinPower = p
|
|
|
|
}
|
|
|
|
{{else}}
|
|
|
|
for _, policy := range builtin{{.}}.PoStProofPolicies {
|
|
|
|
policy.ConsensusMinerMinPower = p
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetMinVerifiedDealSize sets the minimum size of a verified deal. This should
|
|
|
|
// only be used for testing.
|
|
|
|
func SetMinVerifiedDealSize(size abi.StoragePower) {
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
|
|
|
verifreg{{.}}.MinVerifiedDealSize = size
|
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 17:32:00 +00:00
|
|
|
func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) (abi.ChainEpoch, error) {
|
2021-04-26 14:48:20 +00:00
|
|
|
switch ver {
|
|
|
|
{{range .versions}}
|
2021-05-15 01:11:23 +00:00
|
|
|
case actors.Version{{.}}:
|
|
|
|
{{if (eq . 0)}}
|
2021-08-10 17:32:00 +00:00
|
|
|
return miner{{.}}.MaxSealDuration[t], nil
|
2021-05-15 01:11:23 +00:00
|
|
|
{{else}}
|
2021-08-10 17:32:00 +00:00
|
|
|
return miner{{.}}.MaxProveCommitDuration[t], nil
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
default:
|
2021-08-10 17:32:00 +00:00
|
|
|
return 0, xerrors.Errorf("unsupported actors version")
|
2021-05-15 01:11:23 +00:00
|
|
|
}
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 16:54:56 +00:00
|
|
|
// SetProviderCollateralSupplyTarget sets the percentage of normalized circulating
|
|
|
|
// supply that must be covered by provider collateral in a deal. This should
|
|
|
|
// only be used for testing.
|
2021-07-07 17:35:27 +00:00
|
|
|
func SetProviderCollateralSupplyTarget(num, denom big.Int) {
|
|
|
|
{{range .versions}}
|
|
|
|
{{if (ge . 2)}}
|
|
|
|
market{{.}}.ProviderCollateralSupplyTarget = builtin{{.}}.BigFrac{
|
|
|
|
Numerator: num,
|
|
|
|
Denominator: denom,
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
func DealProviderCollateralBounds(
|
|
|
|
size abi.PaddedPieceSize, verified bool,
|
|
|
|
rawBytePower, qaPower, baselinePower abi.StoragePower,
|
|
|
|
circulatingFil abi.TokenAmount, nwVer network.Version,
|
2021-08-10 17:32:00 +00:00
|
|
|
) (min, max abi.TokenAmount, err error) {
|
|
|
|
v, err := actors.VersionForNetwork(nwVer)
|
|
|
|
if err != nil {
|
|
|
|
return big.Zero(), big.Zero(), err
|
|
|
|
}
|
|
|
|
switch v {
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
|
|
|
{{if (eq . 0)}}
|
2021-08-10 17:32:00 +00:00
|
|
|
min, max := market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer)
|
|
|
|
return min, max, nil
|
2021-05-15 01:11:23 +00:00
|
|
|
{{else}}
|
2021-08-10 17:32:00 +00:00
|
|
|
min, max := market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
|
|
|
return min, max, nil
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
default:
|
2021-08-10 17:32:00 +00:00
|
|
|
return big.Zero(), big.Zero(), xerrors.Errorf("unsupported actors version")
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DealDurationBounds(pieceSize abi.PaddedPieceSize) (min, max abi.ChainEpoch) {
|
|
|
|
return market{{.latestVersion}}.DealDurationBounds(pieceSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
|
|
|
miner{{.}}.WPoStChallengeWindow = period
|
|
|
|
miner{{.}}.WPoStProvingPeriod = period * abi.ChainEpoch(miner{{.}}.WPoStPeriodDeadlines)
|
|
|
|
{{if (ge . 3)}}
|
|
|
|
// by default, this is 2x finality which is 30 periods.
|
|
|
|
// scale it if we're scaling the challenge period.
|
|
|
|
miner{{.}}.WPoStDisputeWindow = period * 30
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch {
|
|
|
|
if nwVer <= network.Version3 {
|
|
|
|
return 10
|
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
// NOTE: if this ever changes, adjust it in a (*Miner).mineOne() logline as well
|
2021-04-26 14:48:20 +00:00
|
|
|
return ChainFinality
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMaxSectorExpirationExtension() abi.ChainEpoch {
|
|
|
|
return miner{{.latestVersion}}.MaxSectorExpirationExtension
|
|
|
|
}
|
|
|
|
|
2021-07-11 17:57:09 +00:00
|
|
|
func GetMinSectorExpiration() abi.ChainEpoch {
|
|
|
|
return miner{{.latestVersion}}.MinSectorExpiration
|
|
|
|
}
|
|
|
|
|
2021-06-16 23:39:23 +00:00
|
|
|
func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, error) {
|
2021-04-26 14:48:20 +00:00
|
|
|
sectorsPerPart, err := builtin{{.latestVersion}}.PoStProofWindowPoStPartitionSectors(p)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2021-08-10 17:32:00 +00:00
|
|
|
maxSectors, err := GetAddressedSectorsMax(nv)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return int(uint64(maxSectors) / sectorsPerPart), nil
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetDefaultSectorSize() abi.SectorSize {
|
|
|
|
// supported sector sizes are the same across versions.
|
|
|
|
szs := make([]abi.SectorSize, 0, len(miner{{.latestVersion}}.PreCommitSealProofTypesV8))
|
|
|
|
for spt := range miner{{.latestVersion}}.PreCommitSealProofTypesV8 {
|
|
|
|
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-05-17 18:56:28 +00:00
|
|
|
func GetDefaultAggregationProof() abi.RegisteredAggregationProof {
|
2021-05-27 10:27:47 +00:00
|
|
|
return abi.RegisteredAggregationProof_SnarkPackV1
|
2021-05-17 18:56:28 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version) abi.ChainEpoch {
|
|
|
|
if nwVer <= network.Version10 {
|
2021-05-27 19:54:31 +00:00
|
|
|
return builtin4.SealProofPoliciesV0[proof].SectorMaxLifetime
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return builtin{{.latestVersion}}.SealProofPoliciesV11[proof].SectorMaxLifetime
|
|
|
|
}
|
|
|
|
|
2021-08-10 17:32:00 +00:00
|
|
|
func GetAddressedSectorsMax(nwVer network.Version) (int, error) {
|
|
|
|
v, err := actors.VersionForNetwork(nwVer)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
switch v {
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
2021-08-10 17:32:00 +00:00
|
|
|
return miner{{.}}.AddressedSectorsMax, nil
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
default:
|
2021-08-10 17:32:00 +00:00
|
|
|
return 0, xerrors.Errorf("unsupported network version")
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-10 17:32:00 +00:00
|
|
|
func GetDeclarationsMax(nwVer network.Version) (int, error) {
|
|
|
|
v, err := actors.VersionForNetwork(nwVer)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
switch v {
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
|
|
|
{{if (eq . 0)}}
|
2021-08-10 17:32:00 +00:00
|
|
|
// TODO: Should we instead error here since the concept doesn't exist yet?
|
|
|
|
return miner{{.}}.AddressedPartitionsMax, nil
|
2021-05-15 01:11:23 +00:00
|
|
|
{{else}}
|
2021-08-10 17:32:00 +00:00
|
|
|
return miner{{.}}.DeclarationsMax, nil
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
default:
|
2021-08-10 17:32:00 +00:00
|
|
|
return 0, xerrors.Errorf("unsupported network version")
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-09 01:40:52 +00:00
|
|
|
|
2021-10-01 14:23:21 +00:00
|
|
|
func AggregateProveCommitNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.TokenAmount) (abi.TokenAmount, error) {
|
2021-08-10 17:32:00 +00:00
|
|
|
v, err := actors.VersionForNetwork(nwVer)
|
|
|
|
if err != nil {
|
|
|
|
return big.Zero(), err
|
|
|
|
}
|
|
|
|
switch v {
|
2021-06-09 01:40:52 +00:00
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
2021-10-01 14:23:21 +00:00
|
|
|
{{if (ge . 6)}}
|
|
|
|
return miner{{.}}.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil
|
|
|
|
{{else if (eq . 5)}}
|
|
|
|
return miner{{.}}.AggregateNetworkFee(aggregateSize, baseFee), nil
|
|
|
|
{{else}}
|
2021-08-10 17:32:00 +00:00
|
|
|
return big.Zero(), nil
|
2021-10-01 14:23:21 +00:00
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
default:
|
|
|
|
return big.Zero(), xerrors.Errorf("unsupported network version")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func AggregatePreCommitNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.TokenAmount) (abi.TokenAmount, error) {
|
|
|
|
v, err := actors.VersionForNetwork(nwVer)
|
|
|
|
if err != nil {
|
|
|
|
return big.Zero(), err
|
|
|
|
}
|
|
|
|
switch v {
|
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
|
|
|
{{if (ge . 6)}}
|
|
|
|
return miner{{.}}.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil
|
2021-06-09 01:40:52 +00:00
|
|
|
{{else}}
|
2021-10-01 14:23:21 +00:00
|
|
|
return big.Zero(), nil
|
2021-06-09 01:40:52 +00:00
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
default:
|
2021-08-10 17:32:00 +00:00
|
|
|
return big.Zero(), xerrors.Errorf("unsupported network version")
|
2021-06-09 01:40:52 +00:00
|
|
|
}
|
|
|
|
}
|