gitlab.com/SkynetLabs/skyd@v1.6.9/skymodules/renter/contractor/consts.go (about)

     1  package contractor
     2  
     3  import (
     4  	"gitlab.com/SkynetLabs/skyd/build"
     5  	"go.sia.tech/siad/modules"
     6  	"go.sia.tech/siad/types"
     7  )
     8  
     9  // Constants related to the contractor's alerts.
    10  var (
    11  	// AlertCauseInsufficientAllowanceFunds indicates that the cause for the
    12  	// alert was insufficient allowance funds remaining
    13  	AlertCauseInsufficientAllowanceFunds = "Insufficient allowance funds remaining"
    14  
    15  	// AlertMSGAllowanceLowFunds indicates that forming/renewing a contract during
    16  	// contract maintenance isn't possible due to the allowance being low on
    17  	// funds.
    18  	AlertMSGAllowanceLowFunds = "At least one contract formation/renewal failed due to the allowance being low on funds"
    19  
    20  	// AlertMSGFailedContractRenewal indicates that the contract renewal failed
    21  	AlertMSGFailedContractRenewal = "Contractor is attempting to renew/refresh contracts but failed"
    22  
    23  	// AlertMSGWalletLockedDuringMaintenance indicates that forming/renewing a
    24  	// contract during contract maintenance isn't possible due to a locked wallet.
    25  	AlertMSGWalletLockedDuringMaintenance = "At least one contract failed to form/renew due to the wallet being locked"
    26  )
    27  
    28  // Constants related to contract formation parameters.
    29  var (
    30  	// ContractFeeFundingMulFactor is the multiplying factor for contract fees
    31  	// to determine the funding for a new contract
    32  	ContractFeeFundingMulFactor = uint64(10)
    33  
    34  	// MaxInitialContractFundingDivFactor is the dividing factor for determining
    35  	// the maximum amount of funds to put into a new contract
    36  	MaxInitialContractFundingDivFactor = uint64(3)
    37  
    38  	// MaxInitialContractFundingMulFactor is the multiplying factor for
    39  	// determining the maximum amount of funds to put into a new contract
    40  	MaxInitialContractFundingMulFactor = uint64(2)
    41  
    42  	// MinInitialContractFundingDivFactor is the dividing factor for determining
    43  	// the minimum amount of funds to put into a new contract
    44  	MinInitialContractFundingDivFactor = uint64(20)
    45  
    46  	// ConsecutiveRenewalsBeforeReplacement is the number of times a contract
    47  	// attempt to be renewed before it is marked as !goodForRenew.
    48  	ConsecutiveRenewalsBeforeReplacement = build.Select(build.Var{
    49  		Dev:      types.BlockHeight(12),
    50  		Standard: types.BlockHeight(12), // ~2h
    51  		Testing:  types.BlockHeight(12),
    52  	}).(types.BlockHeight)
    53  
    54  	// MinContractFundRenewalThreshold defines the ratio of remaining funds to
    55  	// total contract cost below which the contractor will prematurely renew a
    56  	// contract.
    57  	//
    58  	// This number is deliberately a little higher than the
    59  	// minContractFundUploadThreshold because we want to make sure that renewals
    60  	// will kick in before uploading stops.
    61  	MinContractFundRenewalThreshold = float64(0.06) // 6%
    62  
    63  	// minContractFundUploadThreshold is the percentage of contract funds
    64  	// remaining at which the contract gets marked !GoodForUpload. The number is
    65  	// high so that there is plenty of money available for downloading, so that
    66  	// urgent repairs can be performed and also so that user file access is not
    67  	// interrupted until after uploading progress is interrupted. Structuring
    68  	// things this way essentially allows the user to experience the failure
    69  	// mode of 'can't store additional stuff' before the user experiences the
    70  	// failure mode of 'can't retrieve stuff already uploaded'.
    71  	MinContractFundUploadThreshold = float64(0.05) // 5%
    72  
    73  	// randomHostsBufferForScore defines how many extra hosts are queried when trying
    74  	// to figure out an appropriate minimum score for the hosts that we have.
    75  	randomHostsBufferForScore = build.Select(build.Var{
    76  		Dev:      2,
    77  		Standard: 50,
    78  		Testing:  1,
    79  	}).(int)
    80  
    81  	// oosRetryInterval is the time we wait for a host that ran out of storage to
    82  	// add more storage before trying to upload to it again.
    83  	oosRetryInterval = build.Select(build.Var{
    84  		Dev:      types.BlockHeight(types.BlocksPerHour / 2), // 30 minutes
    85  		Standard: types.BlockHeight(types.BlocksPerWeek),     // 7 days
    86  		Testing:  types.BlockHeight(types.BlocksPerHour * 2),
    87  	}).(types.BlockHeight)
    88  )
    89  
    90  // Constants related to the safety values for when the contractor is forming
    91  // contracts.
    92  var (
    93  	maxCollateral    = types.SiacoinPrecision.Mul64(1e3) // 1k SC
    94  	maxDownloadPrice = maxStoragePrice.Mul64(3 * uint64(types.BlocksPerMonth))
    95  	maxStoragePrice  = build.Select(build.Var{
    96  		Dev:      types.SiacoinPrecision.Mul64(300e3).Div(modules.BlockBytesPerMonthTerabyte), // 1 order of magnitude greater
    97  		Standard: types.SiacoinPrecision.Mul64(30e3).Div(modules.BlockBytesPerMonthTerabyte),  // 30k SC / TB / Month
    98  		Testing:  types.SiacoinPrecision.Mul64(3e6).Div(modules.BlockBytesPerMonthTerabyte),   // 2 orders of magnitude greater
    99  	}).(types.Currency)
   100  	maxUploadPrice = build.Select(build.Var{
   101  		Dev:      maxStoragePrice.Mul64(30 * uint64(types.BlocksPerMonth)),  // 1 order of magnitude greater
   102  		Standard: maxStoragePrice.Mul64(3 * uint64(types.BlocksPerMonth)),   // 3 months of storage
   103  		Testing:  maxStoragePrice.Mul64(300 * uint64(types.BlocksPerMonth)), // 2 orders of magnitude greater
   104  	}).(types.Currency)
   105  
   106  	// scoreLeewayGoodForRenew defines the factor by which a host can miss the
   107  	// goal score for a set of hosts and still be GoodForRenew. To determine the
   108  	// goal score, a new set of hosts is queried from the hostdb and the lowest
   109  	// scoring among them is selected.  That score is then divided by
   110  	// scoreLeewayGoodForRenew to get the minimum score that a host is allowed
   111  	// to have before being marked as !GoodForRenew.
   112  	//
   113  	// TODO: At this point in time, this value is somewhat arbitrary and could
   114  	// be getting set in a lot more scientific way.
   115  	scoreLeewayGoodForRenew = types.NewCurrency64(500)
   116  
   117  	// scoreLeewayGoodForUpload defines the factor by which a host can miss the
   118  	// goal score for a set of hosts and still be GoodForUpload. To determine the
   119  	// goal score, a new set of hosts is queried from the hostdb and the lowest
   120  	// scoring among them is selected.  That score is then divided by
   121  	// scoreLeewayGoodForUpload to get the minimum score that a host is allowed
   122  	// to have before being marked as !GoodForUpload.
   123  	//
   124  	// Hosts are marked !GoodForUpload before they are marked !GoodForRenew
   125  	// because churn can harm the health and scalability of a user's filesystem.
   126  	// Switching away from adding new files to a host can minimize the damage of
   127  	// using a bad host without incurring data churn.
   128  	//
   129  	// TODO: At this point in time, this value is somewhat arbitrary and could
   130  	// be getting set in a lot more scientific way.
   131  	scoreLeewayGoodForUpload = types.NewCurrency64(40)
   132  )