Skip to content

Commit

Permalink
Disallow increasing O price during the streaming session
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko committed Oct 17, 2023
1 parent 32d5d45 commit 2d8c94b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ func selectOrchestrator(ctx context.Context, n *core.LivepeerNode, params *core.
Balance: balance,
lock: &sync.RWMutex{},
OrchestratorScore: oScore,
InitialPrice: od.RemoteInfo.PriceInfo,
}

sessions = append(sessions, session)
Expand Down
1 change: 1 addition & 0 deletions server/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type BroadcastSession struct {
OrchestratorOS drivers.OSSession
PMSessionID string
Balance Balance
InitialPrice *net.PriceInfo
}

func (bs *BroadcastSession) Transcoder() string {
Expand Down
16 changes: 16 additions & 0 deletions server/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,23 @@ func TestValidatePrice(t *testing.T) {
err = validatePrice(s)
assert.Nil(err)

// O Initial Price == O Price
s.InitialPrice = oinfo.PriceInfo
err = validatePrice(s)
assert.Nil(err)

// O Initial Price higher than O Price
s.InitialPrice = &net.PriceInfo{PricePerUnit: 10, PixelsPerUnit: 3}
err = validatePrice(s)
assert.Nil(err)

// O Initial Price lower than O Price
s.InitialPrice = &net.PriceInfo{PricePerUnit: 1, PixelsPerUnit: 10}
err = validatePrice(s)
assert.ErrorContains(err, "price has changed")

// B MaxPrice < O Price
s.InitialPrice = nil
BroadcastCfg.SetMaxPrice(big.NewRat(1, 5))
err = validatePrice(s)
assert.EqualError(err, fmt.Sprintf("Orchestrator price higher than the set maximum price of %v wei per %v pixels", int64(1), int64(5)))
Expand Down
5 changes: 5 additions & 0 deletions server/segment_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,11 @@ func validatePrice(sess *BroadcastSession) error {
if maxPrice != nil && oPrice.Cmp(maxPrice) == 1 {
return fmt.Errorf("Orchestrator price higher than the set maximum price of %v wei per %v pixels", maxPrice.Num().Int64(), maxPrice.Denom().Int64())
}
iPrice, err := common.RatPriceInfo(sess.InitialPrice)
if err == nil && iPrice != nil && oPrice.Cmp(iPrice) == 1 {
return fmt.Errorf("Orchestrator price has changed, Orchestrator price: %v, Orchestrator initial price: %v", oPrice, iPrice)
}

return nil
}

Expand Down

0 comments on commit 2d8c94b

Please sign in to comment.