Skip to content

Commit 371141a

Browse files
committed
ai/live: Check for a required ManifestID
Help out SDK implementers in case they miss this, since the errors are non-obvious: the orchestrator runs out of balance within a few minutes, even if payments are being sent regularly.
1 parent feb01a9 commit 371141a

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

server/remote_signer.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ func (ls *LivepeerServer) GenerateLivePayment(w http.ResponseWriter, r *http.Req
249249
err error
250250
)
251251
reqState, reqSig := req.State.State, req.State.Sig
252-
if len(reqState) != 0 || len(reqSig) != 0 {
252+
hasState := len(reqState) != 0 || len(reqSig) != 0
253+
if hasState {
253254
if err := verifyStateSignature(ls, reqState, reqSig); err != nil {
254255
err = errors.New("invalid sig")
255256
respondJsonError(ctx, w, err, http.StatusBadRequest)
@@ -279,6 +280,12 @@ func (ls *LivepeerServer) GenerateLivePayment(w http.ResponseWriter, r *http.Req
279280

280281
manifestID := req.ManifestID
281282
if manifestID == "" {
283+
if hasState {
284+
// Required for lv2v so stateful requests stay tied to the same id.
285+
err := errors.New("missing manifestID")
286+
respondJsonError(ctx, w, err, http.StatusBadRequest)
287+
return
288+
}
282289
manifestID = string(core.RandomManifestID())
283290
}
284291
ctx = clog.AddVal(ctx, "manifest_id", manifestID)

server/remote_signer_test.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,40 @@ func TestGenerateLivePayment_StateValidationErrors(t *testing.T) {
359359
}()
360360

361361
tests := []struct {
362-
name string
363-
stateBytes []byte
364-
stateSig []byte
365-
orchInfo *net.OrchestratorInfo
366-
wantStatus int
367-
wantMsg string
362+
name string
363+
stateBytes []byte
364+
stateSig []byte
365+
orchInfo *net.OrchestratorInfo
366+
omitManifestID bool
367+
wantStatus int
368+
wantMsg string
368369
}{
370+
{
371+
name: "missing manifest id with state",
372+
stateBytes: func() []byte {
373+
state, err := json.Marshal(RemotePaymentState{
374+
StateID: "state",
375+
OrchestratorAddress: ethcommon.BytesToAddress(orchInfo.Address),
376+
InitialPricePerUnit: 1,
377+
InitialPixelsPerUnit: 1,
378+
})
379+
require.NoError(err)
380+
return state
381+
}(),
382+
stateSig: func() []byte {
383+
state, err := json.Marshal(RemotePaymentState{
384+
StateID: "state",
385+
OrchestratorAddress: ethcommon.BytesToAddress(orchInfo.Address),
386+
InitialPricePerUnit: 1,
387+
InitialPixelsPerUnit: 1,
388+
})
389+
require.NoError(err)
390+
return sign(state)
391+
}(),
392+
omitManifestID: true,
393+
wantStatus: http.StatusBadRequest,
394+
wantMsg: "missing manifestID",
395+
},
369396
{
370397
name: "invalid state signature",
371398
stateBytes: []byte(`{"stateID":"state","orchestratorAddress":"0x1"}`),
@@ -459,8 +486,14 @@ func TestGenerateLivePayment_StateValidationErrors(t *testing.T) {
459486
orchBlob, err := proto.Marshal(oInfo)
460487
require.NoError(err)
461488

489+
var manifestID string
490+
if !tt.omitManifestID {
491+
manifestID = "manifest"
492+
}
493+
462494
reqBody, err := json.Marshal(RemotePaymentRequest{
463495
Orchestrator: orchBlob,
496+
ManifestID: manifestID,
464497
InPixels: 1,
465498
State: RemotePaymentStateSig{State: tt.stateBytes, Sig: tt.stateSig},
466499
})

0 commit comments

Comments
 (0)