Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Fix host collateral error when renewing contracts #3160

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions modules/renter/proto/renew.go
Expand Up @@ -28,8 +28,8 @@ func (cs *ContractSet) Renew(oldContract *SafeContract, params ContractParams, t
var basePrice, baseCollateral types.Currency
if endHeight+host.WindowSize > lastRev.NewWindowEnd {
timeExtension := uint64((endHeight + host.WindowSize) - lastRev.NewWindowEnd)
basePrice = host.StoragePrice.Mul64(lastRev.NewFileSize).Mul64(timeExtension) // cost of data already covered by contract, i.e. lastrevision.Filesize
baseCollateral = host.Collateral.Mul64(lastRev.NewFileSize).Mul64(timeExtension) // same but collateral
basePrice = host.StoragePrice.Mul64(lastRev.NewFileSize).Mul64(timeExtension) // cost of already uploaded data that needs to be covered by the renewed contract.
baseCollateral = host.Collateral.Mul64(lastRev.NewFileSize).Mul64(timeExtension) // same as basePrice.
}

// Calculate the anticipated transaction fee.
Expand All @@ -48,7 +48,8 @@ func (cs *ContractSet) Renew(oldContract *SafeContract, params ContractParams, t
// Calculate the payouts for the renter, host, and whole contract.
renterPayout := funding.Sub(host.ContractPrice).Sub(txnFee).Sub(basePrice) // renter payout is pre-tax
maxStorageSize := renterPayout.Div(host.StoragePrice)
hostCollateral := maxStorageSize.Mul(host.Collateral)
maxCollateral := maxStorageSize.Mul(host.Collateral) // max collateral the renter can afford with renterPayout
hostCollateral := maxCollateral.Add(baseCollateral)
if hostCollateral.Cmp(host.MaxCollateral) > 0 {
hostCollateral = host.MaxCollateral
}
Expand All @@ -60,8 +61,6 @@ func (cs *ContractSet) Renew(oldContract *SafeContract, params ContractParams, t
// check for negative currency
if types.PostTax(startHeight, totalPayout).Cmp(hostPayout) < 0 {
return modules.RenterContract{}, errors.New("insufficient funds to pay both siafund fee and also host payout")
} else if hostCollateral.Cmp(baseCollateral) < 0 {
return modules.RenterContract{}, errors.New("new collateral smaller than base collateral")
}

// create file contract
Expand Down