gitlab.com/SkynetLabs/skyd@v1.6.9/skymodules/renew.go (about)

     1  package skymodules
     2  
     3  import (
     4  	"go.sia.tech/siad/modules"
     5  	"go.sia.tech/siad/types"
     6  )
     7  
     8  // RenewBaseCosts is a helper to calculate the base costs for a renewed
     9  // contract. The base costs consist of the initial storage cost and collateral
    10  // associated with renewing a contract that already contains data.
    11  // NOTE: The baseCollateral is computed using the maximum acceptable collateral
    12  // to the host. Because of siafund fees, a renter may decide to use less than
    13  // the amount of collateral advertised by the host. If the renter would rather
    14  // have lower collateral and pay fewer siafund fees, they have the full freedom
    15  // within the protocol to do that. It is strictly advantageous for the host.
    16  func RenewBaseCosts(lastRev types.FileContractRevision, pt *modules.RPCPriceTable, endHeight types.BlockHeight) (basePrice, baseCollateral types.Currency) {
    17  	// Get the height until which the storage is already paid for, the height
    18  	// until which we want to pay for storage and the amount of storage that
    19  	// needs to be covered.
    20  	paidForUntil := lastRev.NewWindowEnd
    21  	payForUntil := endHeight + pt.WindowSize
    22  	storage := lastRev.NewFileSize
    23  	// The base is the rpc cost.
    24  	basePrice = pt.RenewContractCost
    25  	// If the storage is already covered, or if there is no data yet, there is
    26  	// no base cost associated with this renewal.
    27  	if paidForUntil >= payForUntil || storage == 0 {
    28  		return
    29  	}
    30  	// Otherwise we calculate the number of blocks we still need to pay for and
    31  	// the amount of cost and collateral expected.
    32  	timeExtension := uint64(payForUntil - paidForUntil)
    33  	basePrice = basePrice.Add(pt.WriteStoreCost.Mul64(storage).Mul64(timeExtension)) // cost of already uploaded data that needs to be covered by the renewed contract.
    34  	baseCollateral = pt.CollateralCost.Mul64(storage).Mul64(timeExtension)           // same as basePrice.
    35  	return
    36  }