2021-05-04 17:53:08 +00:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"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}}
|
2021-05-26 10:33:08 +00:00
|
|
|
{{if (ge . 2)}} builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" {{end}}
|
2021-05-04 17:53:08 +00:00
|
|
|
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-26 10:33:08 +00:00
|
|
|
{{end}}
|
2021-05-04 17:53:08 +00:00
|
|
|
|
2021-05-26 10:33:08 +00:00
|
|
|
paych{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/paych"
|
2021-05-04 17:53:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-05-26 10:33:08 +00:00
|
|
|
ChainFinality = miner{{.latestVersion}}.ChainFinality
|
|
|
|
SealRandomnessLookback = ChainFinality
|
|
|
|
PaychSettleDelay = paych{{.latestVersion}}.SettleDelay
|
2021-05-04 17:53:08 +00:00
|
|
|
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-26 10:33:08 +00:00
|
|
|
{{if (eq . 0)}}
|
|
|
|
miner{{.}}.SupportedProofTypes = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
|
|
|
{{else}}
|
|
|
|
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))
|
|
|
|
{{end}}
|
2021-05-04 17:53:08 +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}}
|
2021-05-26 10:33:08 +00:00
|
|
|
{{if (eq . 0)}}
|
|
|
|
miner{{.}}.SupportedProofTypes[t] = struct{}{}
|
|
|
|
{{else}}
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV0[t] = struct{}{}
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV7[t] = struct{}{}
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
|
|
|
miner{{.}}.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
2021-05-04 17:53:08 +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.
|
2021-05-26 10:33:08 +00:00
|
|
|
{{range .versions}}
|
|
|
|
miner{{.}}.PreCommitChallengeDelay = delay
|
|
|
|
{{end}}
|
2021-05-04 17:53:08 +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-26 10:33:08 +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-05-04 17:53:08 +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-26 10:33:08 +00:00
|
|
|
{{range .versions}}
|
|
|
|
verifreg{{.}}.MinVerifiedDealSize = size
|
|
|
|
{{end}}
|
2021-05-04 17:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) abi.ChainEpoch {
|
|
|
|
switch ver {
|
|
|
|
{{range .versions}}
|
2021-05-26 10:33:08 +00:00
|
|
|
case actors.Version{{.}}:
|
|
|
|
{{if (eq . 0)}}
|
|
|
|
return miner{{.}}.MaxSealDuration[t]
|
|
|
|
{{else}}
|
|
|
|
return miner{{.}}.MaxProveCommitDuration[t]
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
default:
|
|
|
|
panic("unsupported actors version")
|
|
|
|
}
|
2021-05-04 17:53:08 +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) {
|
2021-05-26 10:33:08 +00:00
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
|
|
|
{{if (eq . 0)}}
|
|
|
|
return market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer)
|
|
|
|
{{else}}
|
|
|
|
return market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
2021-05-04 17:53:08 +00:00
|
|
|
default:
|
|
|
|
panic("unsupported actors version")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-26 10:33:08 +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-05-04 17:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch {
|
|
|
|
if nwVer <= network.Version3 {
|
|
|
|
return 10
|
|
|
|
}
|
|
|
|
|
2021-05-26 10:33:08 +00:00
|
|
|
// NOTE: if this ever changes, adjust it in a (*Miner).mineOne() logline as well
|
2021-05-04 17:53:08 +00:00
|
|
|
return ChainFinality
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMaxSectorExpirationExtension() abi.ChainEpoch {
|
|
|
|
return miner{{.latestVersion}}.MaxSectorExpirationExtension
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: we'll probably need to abstract over this better in the future.
|
|
|
|
func GetMaxPoStPartitions(p abi.RegisteredPoStProof) (int, error) {
|
|
|
|
sectorsPerPart, err := builtin{{.latestVersion}}.PoStProofWindowPoStPartitionSectors(p)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return int(miner{{.latestVersion}}.AddressedSectorsMax / sectorsPerPart), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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]
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version) abi.ChainEpoch {
|
|
|
|
if nwVer <= network.Version10 {
|
|
|
|
return builtin{{.latestVersion}}.SealProofPoliciesV0[proof].SectorMaxLifetime
|
|
|
|
}
|
|
|
|
|
|
|
|
return builtin{{.latestVersion}}.SealProofPoliciesV11[proof].SectorMaxLifetime
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetAddressedSectorsMax(nwVer network.Version) int {
|
|
|
|
switch actors.VersionForNetwork(nwVer) {
|
2021-05-26 10:33:08 +00:00
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
|
|
|
return miner{{.}}.AddressedSectorsMax
|
|
|
|
{{end}}
|
2021-05-04 17:53:08 +00:00
|
|
|
default:
|
|
|
|
panic("unsupported network version")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetDeclarationsMax(nwVer network.Version) int {
|
|
|
|
switch actors.VersionForNetwork(nwVer) {
|
2021-05-26 10:33:08 +00:00
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
|
|
|
{{if (eq . 0)}}
|
|
|
|
// TODO: Should we instead panic here since the concept doesn't exist yet?
|
|
|
|
return miner{{.}}.AddressedPartitionsMax
|
|
|
|
{{else}}
|
|
|
|
return miner{{.}}.DeclarationsMax
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
2021-05-04 17:53:08 +00:00
|
|
|
default:
|
|
|
|
panic("unsupported network version")
|
|
|
|
}
|
|
|
|
}
|