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

server: Skip redundant maxPrice check in ongoing session #2994

Merged
merged 5 commits into from
Apr 3, 2024
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#### Broadcaster

- [#2994](https://github.com/livepeer/go-livepeer/pull/2994) server: Skip redundant maxPrice check in ongoing session (@victorges)

#### Orchestrator

#### Transcoder
6 changes: 3 additions & 3 deletions server/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,13 @@ func TestSetOrchestratorPriceInfo(t *testing.T) {
assert.Zero(t, s.LivepeerNode.GetBasePrice("default").Cmp(big.NewRat(1, 1)))

err = s.setOrchestratorPriceInfo("default", "-5", "1", "")
assert.EqualErrorf(t, err, err.Error(), "price unit must be greater than or equal to 0, provided %d\n", -5)
assert.EqualError(t, err, fmt.Sprintf("price unit must be greater than or equal to 0, provided %d", -5))

// pixels per unit <= 0
err = s.setOrchestratorPriceInfo("default", "1", "0", "")
assert.EqualErrorf(t, err, err.Error(), "pixels per unit must be greater than 0, provided %d\n", 0)
assert.EqualError(t, err, fmt.Sprintf("pixels per unit must be greater than 0, provided %d", 0))
err = s.setOrchestratorPriceInfo("default", "1", "-5", "")
assert.EqualErrorf(t, err, err.Error(), "pixels per unit must be greater than 0, provided %d\n", -5)
assert.EqualError(t, err, fmt.Sprintf("pixels per unit must be greater than 0, provided %d", -5))

}
func TestSetPriceForBroadcasterHandler(t *testing.T) {
Expand Down
28 changes: 5 additions & 23 deletions server/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,13 @@ func TestGenPayment(t *testing.T) {
sender := &pm.MockSender{}
s.Sender = sender

// Test invalid price
BroadcastCfg.SetMaxPrice(core.NewFixedPrice(big.NewRat(1, 5)))
// Test changing O price
s.InitialPrice = &net.PriceInfo{PricePerUnit: 1, PixelsPerUnit: 5}
payment, err = genPayment(context.TODO(), s, 1)
assert.Equal("", payment)
assert.Errorf(err, err.Error(), "Orchestrator price higher than the set maximum price of %v wei per %v pixels", int64(1), int64(5))
assert.Errorf(err, "Orchestrator price has changed, Orchestrator price: %v, Orchestrator initial price: %v", "1/3", "1/5")

BroadcastCfg.SetMaxPrice(nil)
s.InitialPrice = nil

// Test CreateTicketBatch error
sender.On("CreateTicketBatch", mock.Anything, mock.Anything).Return(nil, errors.New("CreateTicketBatch error")).Once()
Expand Down Expand Up @@ -680,22 +680,10 @@ func TestValidatePrice(t *testing.T) {
PMSessionID: "foo",
}

// B's MaxPrice is nil
// O's Initial Price is nil
err := validatePrice(s)
assert.Nil(err)

defer BroadcastCfg.SetMaxPrice(nil)

// B MaxPrice > O Price
BroadcastCfg.SetMaxPrice(core.NewFixedPrice(big.NewRat(5, 1)))
err = validatePrice(s)
assert.Nil(err)

// B MaxPrice == O Price
BroadcastCfg.SetMaxPrice(core.NewFixedPrice(big.NewRat(1, 3)))
err = validatePrice(s)
assert.Nil(err)

// O Initial Price == O Price
s.InitialPrice = oinfo.PriceInfo
err = validatePrice(s)
Expand All @@ -711,12 +699,6 @@ func TestValidatePrice(t *testing.T) {
err = validatePrice(s)
assert.ErrorContains(err, "price has changed")

// B MaxPrice < O Price
s.InitialPrice = nil
BroadcastCfg.SetMaxPrice(core.NewFixedPrice(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)))

// O.PriceInfo is nil
s.OrchestratorInfo.PriceInfo = nil
err = validatePrice(s)
Expand Down
4 changes: 0 additions & 4 deletions server/segment_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,6 @@ func validatePrice(sess *BroadcastSession) error {
return errors.New("missing orchestrator price")
}

maxPrice := BroadcastCfg.MaxPrice()
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)
Expand Down
9 changes: 5 additions & 4 deletions server/segment_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1677,14 +1677,15 @@ func TestSubmitSegment_GenPaymentError_ValidatePriceError(t *testing.T) {
Sender: sender,
Balance: balance,
OrchestratorInfo: oinfo,
InitialPrice: &net.PriceInfo{
PricePerUnit: 1,
PixelsPerUnit: 5,
},
}

BroadcastCfg.SetMaxPrice(core.NewFixedPrice(big.NewRat(1, 5)))
defer BroadcastCfg.SetMaxPrice(nil)

_, err := SubmitSegment(context.TODO(), s, &stream.HLSSegment{}, nil, 0, false, true)

assert.EqualErrorf(t, err, err.Error(), "Orchestrator price higher than the set maximum price of %v wei per %v pixels", int64(1), int64(5))
assert.EqualError(t, err, fmt.Sprintf("Orchestrator price has changed, Orchestrator price: %v, Orchestrator initial price: %v", "1/3", "1/5"))
balance.AssertCalled(t, "Credit", existingCredit)
}

Expand Down
Loading