Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/live-runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ parameters. The client retries the same request with `Livepeer-Payment` and
`Livepeer-Segment`, then periodically refreshes payment at
`POST /apps/{runner_id}/session/{session_id}/payment`. The orchestrator accounts
usage on its configured payment interval and releases the session if payment
fails. If the payment unit is `fixed` then payment is only processed once.
fails. The challenge response reports that interval as `payment_interval_ms` so
clients can size and time payments to keep the session balance funded. If the
payment unit is `fixed` then payment is only processed once.

Offchain runners do not issue payment challenges. For the underlying ticket
protocol, see [Payments](payments.md).
Expand Down
15 changes: 9 additions & 6 deletions server/ai_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ type liveRunnerPaymentChallengeResponse struct {
// Keep the URL in top-level JSON so clients do not need to parse the protobuf just to route payment.
Orchestrator string `json:"orchestrator"`
ManifestID string `json:"manifest_id"`
// Interval at which the orchestrator debits the session balance.
PaymentIntervalMs int64 `json:"payment_interval_ms"`
}

type liveRunnerTrickleChannelRequest struct {
Expand Down Expand Up @@ -402,7 +404,7 @@ func (h *lphttp) runnerChallenge(w http.ResponseWriter, r *http.Request, priceIn
respondWithError(w, err.Error(), http.StatusInternalServerError)
return
}
data, err := marshalLivePaymentChallengeResponse(oInfo)
data, err := marshalLivePaymentChallengeResponse(oInfo, h.node.LivePaymentInterval)
if err != nil {
respondWithError(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -427,7 +429,7 @@ func (h *lphttp) scopePaymentChallenge(w http.ResponseWriter, r *http.Request) (
if err != nil {
return false, err
}
data, err := marshalLivePaymentChallengeResponse(oInfo)
data, err := marshalLivePaymentChallengeResponse(oInfo, h.node.LivePaymentInterval)
if err != nil {
return false, err
}
Expand All @@ -437,15 +439,16 @@ func (h *lphttp) scopePaymentChallenge(w http.ResponseWriter, r *http.Request) (
return true, nil
}

func marshalLivePaymentChallengeResponse(oInfo *lpnet.OrchestratorInfo) ([]byte, error) {
func marshalLivePaymentChallengeResponse(oInfo *lpnet.OrchestratorInfo, paymentInterval time.Duration) ([]byte, error) {
buf, err := proto.Marshal(oInfo)
if err != nil {
return nil, err
}
return json.Marshal(liveRunnerPaymentChallengeResponse{
PaymentParams: base64.StdEncoding.EncodeToString(buf),
Orchestrator: oInfo.GetTranscoder(),
ManifestID: oInfo.GetAuthToken().GetSessionId(),
PaymentParams: base64.StdEncoding.EncodeToString(buf),
Orchestrator: oInfo.GetTranscoder(),
ManifestID: oInfo.GetAuthToken().GetSessionId(),
PaymentIntervalMs: paymentInterval.Milliseconds(),
})
}

Expand Down
1 change: 1 addition & 0 deletions server/ai_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ func TestLiveRunnerReserveSessionOnchainReturnsPaymentChallenge(t *testing.T) {
require.NotEmpty(t, challenge.PaymentParams)
require.Equal(t, lp.orchestrator.ServiceURI().String(), challenge.Orchestrator)
require.NotEmpty(t, challenge.ManifestID)
require.Equal(t, int64(5000), challenge.PaymentIntervalMs)
require.Equal(t, challenge.ManifestID, oInfo.GetAuthToken().GetSessionId())
require.NotNil(t, oInfo.GetTicketParams())
require.NotNil(t, oInfo.GetPriceInfo())
Expand Down
2 changes: 1 addition & 1 deletion server/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (h *lphttp) RefreshPayment(w http.ResponseWriter, r *http.Request) {
}

w.Header().Set("Content-Type", "application/json")
data, err := marshalLivePaymentChallengeResponse(oInfo)
data, err := marshalLivePaymentChallengeResponse(oInfo, h.node.LivePaymentInterval)
if err != nil {
respondJsonError(ctx, w, err, http.StatusInternalServerError)
return
Expand Down
Loading