Skip to content

Add flag 'ignoreMaxPriceIfNeeded' #3127

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

Merged
merged 7 commits into from
Aug 20, 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
1 change: 1 addition & 0 deletions cmd/livepeer/livepeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func parseLivepeerConfig() starter.LivepeerConfig {
cfg.OrchPerfStatsURL = flag.String("orchPerfStatsUrl", *cfg.OrchPerfStatsURL, "URL of Orchestrator Performance Stream Tester")
cfg.Region = flag.String("region", *cfg.Region, "Region in which a broadcaster is deployed; used to select the region while using the orchestrator's performance stats")
cfg.MaxPricePerUnit = flag.String("maxPricePerUnit", *cfg.MaxPricePerUnit, "The maximum transcoding price per 'pixelsPerUnit' a broadcaster is willing to accept. If not set explicitly, broadcaster is willing to accept ANY price. Can be specified in wei or a custom currency in the format <price><currency> (e.g. 0.50USD). When using a custom currency, a corresponding price feed must be configured with -priceFeedAddr")
cfg.IgnoreMaxPriceIfNeeded = flag.Bool("ignoreMaxPriceIfNeeded", *cfg.IgnoreMaxPriceIfNeeded, "Set to true to allow exceeding max price condition if there is no O that meets this requirement")
cfg.MinPerfScore = flag.Float64("minPerfScore", *cfg.MinPerfScore, "The minimum orchestrator's performance score a broadcaster is willing to accept")

// Transcoding:
Expand Down
14 changes: 9 additions & 5 deletions cmd/livepeer/starter/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
OrchPerfStatsURL *string
Region *string
MaxPricePerUnit *string
IgnoreMaxPriceIfNeeded *bool
MinPerfScore *float64
MaxSessions *string
CurrentManifest *bool
Expand Down Expand Up @@ -204,6 +205,7 @@
defaultMaxTotalEV := "20000000000000"
defaultDepositMultiplier := 1
defaultMaxPricePerUnit := "0"
defaultIgnoreMaxPriceIfNeeded := false

Check warning on line 208 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L208

Added line #L208 was not covered by tests
defaultPixelsPerUnit := "1"
defaultPriceFeedAddr := "0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612" // ETH / USD price feed address on Arbitrum Mainnet
defaultAutoAdjustPrice := true
Expand Down Expand Up @@ -294,6 +296,7 @@
MaxTotalEV: &defaultMaxTotalEV,
DepositMultiplier: &defaultDepositMultiplier,
MaxPricePerUnit: &defaultMaxPricePerUnit,
IgnoreMaxPriceIfNeeded: &defaultIgnoreMaxPriceIfNeeded,

Check warning on line 299 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L299

Added line #L299 was not covered by tests
PixelsPerUnit: &defaultPixelsPerUnit,
PriceFeedAddr: &defaultPriceFeedAddr,
AutoAdjustPrice: &defaultAutoAdjustPrice,
Expand Down Expand Up @@ -1588,11 +1591,12 @@
*cfg.SelectStakeWeight, *cfg.SelectPriceWeight, *cfg.SelectRandWeight)
}
return server.ProbabilitySelectionAlgorithm{
MinPerfScore: *cfg.MinPerfScore,
StakeWeight: *cfg.SelectStakeWeight,
PriceWeight: *cfg.SelectPriceWeight,
RandWeight: *cfg.SelectRandWeight,
PriceExpFactor: *cfg.SelectPriceExpFactor,
MinPerfScore: *cfg.MinPerfScore,
StakeWeight: *cfg.SelectStakeWeight,
PriceWeight: *cfg.SelectPriceWeight,
RandWeight: *cfg.SelectRandWeight,
PriceExpFactor: *cfg.SelectPriceExpFactor,
IgnoreMaxPriceIfNeeded: *cfg.IgnoreMaxPriceIfNeeded,

Check warning on line 1599 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L1594-L1599

Added lines #L1594 - L1599 were not covered by tests
}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions server/selection_algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type ProbabilitySelectionAlgorithm struct {
PriceWeight float64
RandWeight float64

PriceExpFactor float64
PriceExpFactor float64
IgnoreMaxPriceIfNeeded bool
}

func (sa ProbabilitySelectionAlgorithm) Select(ctx context.Context, addrs []ethcommon.Address, stakes map[ethcommon.Address]int64, maxPrice *big.Rat, prices map[ethcommon.Address]*big.Rat, perfScores map[ethcommon.Address]float64) ethcommon.Address {
Expand Down Expand Up @@ -70,7 +71,7 @@ func (sa ProbabilitySelectionAlgorithm) filterByMaxPrice(ctx context.Context, ad
}
}

if len(res) == 0 {
if len(res) == 0 && sa.IgnoreMaxPriceIfNeeded {
// If no orchestrators pass the filter, return all Orchestrators
// It means that no orchestrators are below the max price
clog.Warningf(ctx, "No Orchestrators passed max price filter, not using the filter, numAddrs=%d, maxPrice=%v, prices=%v, addrs=%v", len(addrs), maxPrice, prices, addrs)
Expand Down
48 changes: 36 additions & 12 deletions server/selection_algorithm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ const testPriceExpFactor = 100

func TestFilter(t *testing.T) {
tests := []struct {
name string
orchMinPerfScore float64
maxPrice float64
prices map[string]float64
orchPerfScores map[string]float64
orchestrators []string
want []string
name string
orchMinPerfScore float64
maxPrice float64
prices map[string]float64
orchPerfScores map[string]float64
orchestrators []string
want []string
ignoreMaxPriceIfNeeded bool
}{
{
name: "Some Orchestrators pass the filter",
Expand Down Expand Up @@ -91,7 +92,7 @@ func TestFilter(t *testing.T) {
},
},
{
name: "All prices below max price",

orchMinPerfScore: 0.7,
maxPrice: 2000,
prices: map[string]float64{
Expand All @@ -115,9 +116,10 @@ func TestFilter(t *testing.T) {
},
},
{
name: "All prices above max price",
orchMinPerfScore: 0.7,
maxPrice: 100,
name: "All prices above max price and ignoreMaxPriceIfNeeded enabled",
orchMinPerfScore: 0.7,
maxPrice: 100,
ignoreMaxPriceIfNeeded: true,
prices: map[string]float64{
"0x0000000000000000000000000000000000000001": 500,
"0x0000000000000000000000000000000000000002": 1500,
Expand All @@ -138,6 +140,27 @@ func TestFilter(t *testing.T) {
"0x0000000000000000000000000000000000000003",
},
},
{
name: "All prices below max price",
orchMinPerfScore: 0.7,
maxPrice: 100,
prices: map[string]float64{
"0x0000000000000000000000000000000000000001": 500,
"0x0000000000000000000000000000000000000002": 1500,
"0x0000000000000000000000000000000000000003": 1000,
},
orchPerfScores: map[string]float64{
"0x0000000000000000000000000000000000000001": 0.6,
"0x0000000000000000000000000000000000000002": 0.8,
"0x0000000000000000000000000000000000000003": 0.9,
},
orchestrators: []string{
"0x0000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000002",
"0x0000000000000000000000000000000000000003",
},
want: []string{},
},
{
name: "Mix of prices relative to max price",
orchMinPerfScore: 0.7,
Expand Down Expand Up @@ -206,7 +229,8 @@ func TestFilter(t *testing.T) {
maxPrice = new(big.Rat).SetFloat64(tt.maxPrice)
}
sa := &ProbabilitySelectionAlgorithm{
MinPerfScore: tt.orchMinPerfScore,
MinPerfScore: tt.orchMinPerfScore,
IgnoreMaxPriceIfNeeded: tt.ignoreMaxPriceIfNeeded,
}

res := sa.filter(context.Background(), addrs, maxPrice, prices, perfScores)
Expand Down
Loading