-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compute new collateral for renewals in worker instead of the autopilot #811
Conversation
b56614d
to
4ad17ae
Compare
autopilot/contractor.go
Outdated
@@ -1387,8 +1394,8 @@ func (c *contractor) renewContract(ctx context.Context, w Worker, ci contractInf | |||
*budget = budget.Sub(renterFunds) | |||
|
|||
// persist the contract | |||
contractPrice := newRevision.Revision.MissedHostPayout().Sub(newCollateral) | |||
renewedContract, err := c.ap.bus.AddRenewedContract(ctx, newRevision, contractPrice, renterFunds, cs.BlockHeight, fcid, api.ContractStatePending) | |||
newCollateral := resp.Contract.Revision.MissedHostPayout().Sub(resp.ContractPrice) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
maybe move this down so it's clear this is used for logging purposes only
} | ||
|
||
// RHPRenewResponse is the response type for the /rhp/renew endpoint. | ||
RHPRenewResponse struct { | ||
Error string `json:"error"` | ||
ContractID types.FileContractID `json:"contractID"` | ||
Contract rhpv2.ContractRevision `json:"contract"` | ||
ContractPrice types.Currency `json:"contractPrice"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to drop ContractID
from RHPRenewResponse
? It's duplicated info.
Does it make sense to return the renewCollateral
directly instead of the ContractPrice
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ContractPrice
is the thing we actually need for the next API call. So I'm returning it instead of the thing we only need for logging. At the end of the day it doesn't really matter cause the endpoint will be removed with rhpv4 anyway once we remove anything related to contracts to the bus.
That way we can do so after locking the contract to avoid exceeding the max collateral when uploading at the same time.
As a side - effect, since we only pass a pricetable to
RPCRenew
, we also use rhpv3 estimates now.