refactor: renterd allowance derived max pricing #647
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Status: Ready for review
The PR adds a default option to automatically calculate max gouging prices from the user configured usage estimates and allowance.
I don't think the previous simpler
f(allowance, percents) => pricing
version really captured the intended behaviour so I expanded the equation to incorporate the user estimates, while proportionally fixing the prices according to configurable weights, default: 10% upload, 50% download, 40% storage. Let me know if this solution makes sense.The
derivePricingFromAllowance
method calculates the max price per TB for storage, download, and upload given a total spending allowance and estimated usage in TB for each type. The prices are kept proportional to each other using the weight factors provided as parameters. Storage and upload are also scaled by the redundancy multiplier.The total cost equation is:
Once the unit cost is determined, the individual prices can be calculated:
The function also includes an allowance scaling factor to account for contract price variation. For example, if a user expects to pay $2 per TB, they should set the max value to $4 per TB because the optimal contracts may vary, eg: one contract at $1 and another at $3 which average to $2. The scaling factor helps avoid unnecessary churn.