2020-09-23 19:24:51 +00:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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"
|
2020-09-23 19:24:51 +00:00
|
|
|
|
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"
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ChainFinality = miner0.ChainFinality
|
|
|
|
SealRandomnessLookback = ChainFinality
|
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) {
|
|
|
|
newTypes := make(map[abi.RegisteredSealProof]struct{}, len(types))
|
|
|
|
for _, t := range types {
|
|
|
|
newTypes[t] = struct{}{}
|
|
|
|
}
|
|
|
|
// Set for all miner versions.
|
|
|
|
miner0.SupportedProofTypes = newTypes
|
2020-09-29 00:28:16 +00:00
|
|
|
miner2.SupportedProofTypes = newTypes
|
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-09-25 21:33:25 +00:00
|
|
|
// Set for all miner versions.
|
|
|
|
miner0.SupportedProofTypes[t] = struct{}{}
|
2020-09-29 00:28:16 +00:00
|
|
|
miner2.SupportedProofTypes[t] = 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
|
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
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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]
|
|
|
|
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)
|
|
|
|
default:
|
|
|
|
panic("unsupported network version")
|
|
|
|
}
|
|
|
|
}
|