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

-autoAdjustPrice flag to enable/disable automatic price adjustments #2025

Merged
merged 3 commits into from
Sep 10, 2021
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 @@ -11,6 +11,8 @@

#### Orchestrator

- \#2025 Add -autoAdjustPrice flag to enable/disable automatic price adjustments (@yondonfu)

#### Transcoder

- \#1979 Upgrade to ffmpeg v4.4 and improved API for (experimental) AI tasks (@jailuthra)
Expand Down
3 changes: 3 additions & 0 deletions cmd/livepeer/livepeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func main() {
maxPricePerUnit := flag.Int("maxPricePerUnit", 0, "The maximum transcoding price (in wei) per 'pixelsPerUnit' a broadcaster is willing to accept. If not set explicitly, broadcaster is willing to accept ANY price")
// Unit of pixels for both O's basePriceInfo and B's MaxBroadcastPrice
pixelsPerUnit := flag.Int("pixelsPerUnit", 1, "Amount of pixels per unit. Set to '> 1' to have smaller price granularity than 1 wei / pixel")
autoAdjustPrice := flag.Bool("autoAdjustPrice", true, "Enable/disable automatic price adjustments based on the overhead for redeeming tickets")
// Interval to poll for blocks
blockPollingInterval := flag.Int("blockPollingInterval", 5, "Interval in seconds at which different blockchain event services poll for blocks")
// Redemption service
Expand Down Expand Up @@ -562,6 +563,8 @@ func main() {
n.SetBasePrice(big.NewRat(int64(*pricePerUnit), int64(*pixelsPerUnit)))
glog.Infof("Price: %d wei for %d pixels\n ", *pricePerUnit, *pixelsPerUnit)

n.AutoAdjustPrice = *autoAdjustPrice

ev, _ := new(big.Int).SetString(*ticketEV, 10)
if ev == nil {
glog.Errorf("-ticketEV must be a valid integer, but %v provided. Restart the node with a different valid value for -ticketEV", *ticketEV)
Expand Down
12 changes: 7 additions & 5 deletions core/livepeernode.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type LivepeerNode struct {
TranscoderManager *RemoteTranscoderManager
Balances *AddressBalances
Capabilities *Capabilities
AutoAdjustPrice bool

// Broadcaster public fields
Sender pm.Sender
Expand All @@ -95,11 +96,12 @@ type LivepeerNode struct {
func NewLivepeerNode(e eth.LivepeerEthClient, wd string, dbh *common.DB) (*LivepeerNode, error) {
rand.Seed(time.Now().UnixNano())
return &LivepeerNode{
Eth: e,
WorkDir: wd,
Database: dbh,
SegmentChans: make(map[ManifestID]SegmentChan),
segmentMutex: &sync.RWMutex{},
Eth: e,
WorkDir: wd,
Database: dbh,
AutoAdjustPrice: true,
SegmentChans: make(map[ManifestID]SegmentChan),
segmentMutex: &sync.RWMutex{},
}, nil
}

Expand Down
10 changes: 10 additions & 0 deletions core/orch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,16 @@ func TestPriceInfo(t *testing.T) {
expPrice = common.FixedToPrice(fixedPrice)
assert.Equal(priceInfo.PricePerUnit, expPrice.Num().Int64())
assert.Equal(priceInfo.PixelsPerUnit, expPrice.Denom().Int64())

// Test when AutoAdjustPrice = false
// First make sure when AutoAdjustPrice = true we are not returning the base price
assert.NotEqual(basePrice, big.NewRat(priceInfo.PricePerUnit, priceInfo.PixelsPerUnit))

// Now make sure when AutoAdjustPrice = false we are returning the base price
n.AutoAdjustPrice = false
priceInfo, err = orch.PriceInfo(ethcommon.Address{})
assert.Nil(err)
assert.Equal(basePrice, big.NewRat(priceInfo.PricePerUnit, priceInfo.PixelsPerUnit))
}

func TestPriceInfo_GivenNilNode_ReturnsNilError(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions core/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ func (orch *orchestrator) PriceInfo(sender ethcommon.Address) (*net.PriceInfo, e
// priceInfo returns price per pixel as a fixed point number wrapped in a big.Rat
func (orch *orchestrator) priceInfo(sender ethcommon.Address) (*big.Rat, error) {
basePrice := orch.node.GetBasePrice()

if !orch.node.AutoAdjustPrice {
return basePrice, nil
}

// If price = 0, overhead is 1
// If price > 0, overhead = 1 + (1 / txCostMultiplier)
overhead := big.NewRat(1, 1)
Expand Down