implement file contract renew host-side #1149

Merged
merged 2 commits into from May 16, 2016

Projects

None yet

2 participants

@DavidVorick
Member

This code is a combination of FormContract and ReviseContract code, though there is some unique stuff with regards to how payouts are managed.

@lukechampine lukechampine commented on an outdated diff May 14, 2016
modules/host/negotiateformcontract.go
@@ -43,6 +46,10 @@ var (
// which is longer than the host's maximum duration.
errDurationTooLong = errors.New("file contract has a duration which exceeds the duration permitted by the host")
+ // errEmptyFileContractTransactionSet is returned if the renter provides a
+ // nil file contract transaction set during file contract negotiation.
+ errEmptyFileContractTransactionSet = errors.New("file contract transaction set is nil - invalid!")
@lukechampine
lukechampine May 14, 2016 Member

file contract transaction set is nil is fine. Errors aren't supposed to have punctuation.

@DavidVorick
Member

Does the rest of this look alright?

@lukechampine lukechampine commented on an outdated diff May 16, 2016
modules/host/negotiaterenewcontract.go
+ // presented which does not extend the existing file contract.
+ errRenewDoesNotExtend = errors.New("file contract renewal does not extend the existing file contract")
+)
+
+// renewBaseCollateral returns the base collateral on the storage in the file
+// contract, using the host's external settings and the starting file contract.
+func renewBaseCollateral(so *storageObligation, settings modules.HostExternalSettings, txnSet []types.Transaction) types.Currency {
+ fc := txnSet[len(txnSet)-1].FileContracts[0]
+ timeExtension := fc.WindowEnd - so.proofDeadline()
+ return settings.Collateral.Mul64(fc.FileSize).Mul64(uint64(timeExtension))
+}
+
+// renewBasePrice returns the base cost of the storage in the file contract,
+// using the host external settings and the starting file contract.
+func renewBasePrice(so *storageObligation, settings modules.HostExternalSettings, txnSet []types.Transaction) types.Currency {
+ fc := txnSet[len(txnSet)-1].FileContracts[0]
@lukechampine
lukechampine May 16, 2016 Member

why do these functions take txnSet rather than fc directly?

@lukechampine lukechampine commented on the diff May 16, 2016
modules/host/negotiaterenewcontract.go
+ // renter's public key in the unlock conditions that protect the file
+ // contract from revision.
+ var txnSet []types.Transaction
+ var renterPK crypto.PublicKey
+ err = encoding.ReadObject(conn, &txnSet, modules.NegotiateMaxFileContractSetLen)
+ if err != nil {
+ return err
+ }
+ err = encoding.ReadObject(conn, &renterPK, modules.NegotiateMaxSiaPubkeySize)
+ if err != nil {
+ return err
+ }
+
+ h.mu.RLock()
+ settings := h.externalSettings()
+ h.mu.RUnlock()
@lukechampine
lukechampine May 16, 2016 Member

what happens if the user changes their settings between h.managedRPCSettings and h.externalSettings()? I assume the host may reject the renewal, or send terms that the renter will reject. This behavior seems fine to me, just something to be aware of.

@DavidVorick
DavidVorick May 16, 2016 Member

I thought about sending the settings around starting from the beginning of the connection, but this is a rare race condition and it will be handled mostly gracefully. The host will either reject the renter's file contract, or nothing unusual will happen. Host will only reject the renter if the price goes up, nothing happens if the price goes down.

This is something that can reasonably be addressed later. Might be a larger issue once the host is automatically adjusting prices to meet supply + demand.

@lukechampine
Member

Yeah, seems almost identical to FormContract, which is good

@DavidVorick
Member

ok, I should be able to get to all of this before bed tonight.

@DavidVorick DavidVorick functions take less input
The whole transaction set was being passed to functions that were only
use the file contract.

Now only the file contract is used as a parameter.
c6e3a72
@lukechampine lukechampine merged commit 8d9d65d into master May 16, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@DavidVorick DavidVorick deleted the host-renew branch May 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment