Skip to content
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

Retrieval Provider Can Set Unseal Price #325

Closed
hannahhoward opened this issue Jul 15, 2020 · 0 comments · Fixed by #330
Closed

Retrieval Provider Can Set Unseal Price #325

hannahhoward opened this issue Jul 15, 2020 · 0 comments · Fixed by #330
Assignees

Comments

@hannahhoward
Copy link
Collaborator

As a retrieval provider, I want to be able to set an unseal price for my retrieval deals, so that I am paid for the CPU power required to unseal a sector.

Suggested Steps (not required-- just one path that will work:

  • Add to QueryResponse:
    • UnsealPrice = abi.TokenAmount
  • Add to Params & NewParamsV1:
    • UnsealPrice = abi.TokenAmount
  • Implement retrievalprovider.SetPricePerUnseal (can just save instance var)
  • Add UnsealPrice from params to providerValidationEnvironment.CheckDealParams
    On Provider:
  • In ProviderValidator if UnsealPrice > 0, rather than returning status of rm.DealStatusAccepted, return new rm.DealStatusFundsNeededUnseal status. Return UnsealPrice for PaymentOwed
    -- Make sure to dispatch ProviderEventPaymentRequested to put you in a rm.DealStatusFundsNeededUnseal state rather than a rm.DealStatusUnsealing state on Provider
    (recommend modifying BeginTracking for providerValidationEnvironment in provider_environment.go, if UnsealPrice > 0, dispatch ProviderEventPaymentRequested rather than ProviderEventOpen, add transition on ProviderEventPaymentRequested to go from DealStatusNew to DealStatusFundsNeededUnseal)
    On client
  • Make sure to dispatch an rm.ClientEventPaymentRequested event with PaymentOwed
  • Let client payment channel creation proceed as normal
  • Add UnsealFundsPaid abi.TokenAmount to client deal
  • In handler clientstates.ProcessPaymentRequested for client_states, add check to determine if unseal payments are owed (deal.UnsealPrice > deal.UnsealFundsPaid as additional OR condition on the if check)
  • In SendFunds state handler, augment the payment requested check. Currently, its essentially:
    paymentRequested <= (totalReceived - bytesPaidFor) * pricePerByte
    Now it should be:
    paymentRequested <= ((totalReceived - bytesPaidFor) * pricePerByte)+ (UnsealPrice -UnsealFundsPaid))
  • In state handler for ClientEventPaymentSent,
    currently we do:
			bytesPaidFor := big.Div(deal.PaymentRequested, deal.PricePerByte).Uint64()

Now we should probably first pay the unseal funds

paymentForUnsealing = min(deal.PaymentRequested, deal.UnsealPrice - deal.UnsealPaidFor)
deal.UnsealPaidFor += paymentForUnsealing
bytesPaidFor = big.Div(deal.PaymentRequest - paymentForUnsealing, deal.PricePerByte).Uint64)

(or something like that)

  • OnProvider:
  • In ProviderRevalidor, augment to calculation of TotalPaidFor:
	channel.totalPaidFor = big.Div(deal.FundsReceived, deal.PricePerByte).Uint64()

to

	channel.totalPaidFor = big.Div(max(deal.FundsReceived-deal.UnsealPrice, 0), deal.PricePerByte).Uint64()
  • Augment the ProviderRevalidator Revalidate to factor in Unseal price into payment owed:
	paymentOwed := big.Sub(big.Mul(abi.NewTokenAmount(int64(deal.TotalSent)), deal.PricePerByte), deal.FundsReceived)

to

	paymentOwed := big.Sub(big.Add(big.Mul(abi.NewTokenAmount(int64(deal.TotalSent)), deal.PricePerByte), deal.UnsealPrice), deal.FundsReceived)
  • When dispatching ProviderEventPaymentReceived make sure rm.DealStatusFundsNeededUnseal transitions to DealStatusUnsealing
hannahhoward pushed a commit that referenced this issue Jul 23, 2020
* WIP

* Make selector required for retrieval deal params V1

* Add provider states for unsealing funds

* Fix up channel tracking and payment flow for unsealing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants