From 8c8392193b9199c8ccb9e6ef8ac47be2305cd0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Leszko?= Date: Mon, 19 Aug 2024 10:41:19 +0200 Subject: [PATCH] Change enforceMaxPrice to ignoreMaxPriceIfNeeded --- cmd/livepeer/livepeer.go | 2 +- cmd/livepeer/starter/starter.go | 16 +++++++-------- server/selection_algorithm.go | 6 +++--- server/selection_algorithm_test.go | 32 +++++++++++++++--------------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cmd/livepeer/livepeer.go b/cmd/livepeer/livepeer.go index 614d7466c9..d28b579a32 100755 --- a/cmd/livepeer/livepeer.go +++ b/cmd/livepeer/livepeer.go @@ -135,7 +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 (e.g. 0.50USD). When using a custom currency, a corresponding price feed must be configured with -priceFeedAddr") - cfg.EnforceMaxPrice = flag.Bool("enforceMaxPrice", *cfg.EnforceMaxPrice, "Set to true to enforce the maximum price per unit; if set to false and no O satisfies the max price condition, broadcaster selects an O with the price higher than maxPricePerUnit") + 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: diff --git a/cmd/livepeer/starter/starter.go b/cmd/livepeer/starter/starter.go index 564431fdfa..04d5876d2b 100755 --- a/cmd/livepeer/starter/starter.go +++ b/cmd/livepeer/starter/starter.go @@ -99,7 +99,7 @@ type LivepeerConfig struct { OrchPerfStatsURL *string Region *string MaxPricePerUnit *string - EnforceMaxPrice *bool + IgnoreMaxPriceIfNeeded *bool MinPerfScore *float64 MaxSessions *string CurrentManifest *bool @@ -296,7 +296,7 @@ func DefaultLivepeerConfig() LivepeerConfig { MaxTotalEV: &defaultMaxTotalEV, DepositMultiplier: &defaultDepositMultiplier, MaxPricePerUnit: &defaultMaxPricePerUnit, - EnforceMaxPrice: &defaultEnforceMaxPrice, + IgnoreMaxPriceIfNeeded: &defaultEnforceMaxPrice, PixelsPerUnit: &defaultPixelsPerUnit, PriceFeedAddr: &defaultPriceFeedAddr, AutoAdjustPrice: &defaultAutoAdjustPrice, @@ -1591,12 +1591,12 @@ func createSelectionAlgorithm(cfg LivepeerConfig) (common.SelectionAlgorithm, er *cfg.SelectStakeWeight, *cfg.SelectPriceWeight, *cfg.SelectRandWeight) } return server.ProbabilitySelectionAlgorithm{ - MinPerfScore: *cfg.MinPerfScore, - StakeWeight: *cfg.SelectStakeWeight, - PriceWeight: *cfg.SelectPriceWeight, - RandWeight: *cfg.SelectRandWeight, - PriceExpFactor: *cfg.SelectPriceExpFactor, - EnforceMaxPrice: *cfg.EnforceMaxPrice, + MinPerfScore: *cfg.MinPerfScore, + StakeWeight: *cfg.SelectStakeWeight, + PriceWeight: *cfg.SelectPriceWeight, + RandWeight: *cfg.SelectRandWeight, + PriceExpFactor: *cfg.SelectPriceExpFactor, + IgnoreMaxPriceIfNeeded: *cfg.IgnoreMaxPriceIfNeeded, }, nil } diff --git a/server/selection_algorithm.go b/server/selection_algorithm.go index 4b6b2f6c43..8ea304002b 100644 --- a/server/selection_algorithm.go +++ b/server/selection_algorithm.go @@ -20,8 +20,8 @@ type ProbabilitySelectionAlgorithm struct { PriceWeight float64 RandWeight float64 - PriceExpFactor float64 - EnforceMaxPrice bool + 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 { @@ -71,7 +71,7 @@ func (sa ProbabilitySelectionAlgorithm) filterByMaxPrice(ctx context.Context, ad } } - if len(res) == 0 && !sa.EnforceMaxPrice { + 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) diff --git a/server/selection_algorithm_test.go b/server/selection_algorithm_test.go index 4b7d8fe0c0..61b966b42e 100644 --- a/server/selection_algorithm_test.go +++ b/server/selection_algorithm_test.go @@ -13,14 +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 - enforceMaxPrice bool + 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", @@ -92,7 +92,7 @@ func TestFilter(t *testing.T) { }, }, { - name: "All prices below max price", + orchMinPerfScore: 0.7, maxPrice: 2000, prices: map[string]float64{ @@ -116,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, @@ -140,10 +141,9 @@ func TestFilter(t *testing.T) { }, }, { - name: "All prices above max price and enforceMaxPrice enabled", + name: "All prices below max price", orchMinPerfScore: 0.7, maxPrice: 100, - enforceMaxPrice: true, prices: map[string]float64{ "0x0000000000000000000000000000000000000001": 500, "0x0000000000000000000000000000000000000002": 1500, @@ -229,8 +229,8 @@ func TestFilter(t *testing.T) { maxPrice = new(big.Rat).SetFloat64(tt.maxPrice) } sa := &ProbabilitySelectionAlgorithm{ - MinPerfScore: tt.orchMinPerfScore, - EnforceMaxPrice: tt.enforceMaxPrice, + MinPerfScore: tt.orchMinPerfScore, + IgnoreMaxPriceIfNeeded: tt.ignoreMaxPriceIfNeeded, } res := sa.filter(context.Background(), addrs, maxPrice, prices, perfScores)