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

Fix setting fixed price per session with initial price 0 #2904

Merged
merged 3 commits into from
Nov 2, 2023
Merged
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
33 changes: 21 additions & 12 deletions core/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,17 @@
return nil
}

if payment.TicketParams == nil {
return nil
}

if payment.Sender == nil || len(payment.Sender) == 0 {
if (payment.Sender == nil || len(payment.Sender) == 0) && payment.TicketParams != nil {
return fmt.Errorf("Could not find Sender for payment: %v", payment)
}

sender := ethcommon.BytesToAddress(payment.Sender)

if payment.TicketParams == nil {
// No ticket params means that the price is 0, then set the fixed price per session to 0
orch.setFixedPricePerSession(sender, manifestID, big.NewRat(0, 1))
return nil
}

recipientAddr := ethcommon.BytesToAddress(payment.TicketParams.Recipient)
ok, err := orch.isActive(recipientAddr)
if err != nil {
Expand All @@ -141,12 +142,7 @@
}

// During the first payment, set the fixed price per session
if balances, ok := orch.node.Balances.balances[sender]; ok {
if balances.FixedPrice(manifestID) == nil {
balances.SetFixedPrice(manifestID, priceInfoRat)
glog.V(6).Infof("Setting fixed price=%v for session=%v", priceInfoRat, manifestID)
}
}
orch.setFixedPricePerSession(sender, manifestID, priceInfoRat)

ticketParams := &pm.TicketParams{
Recipient: ethcommon.BytesToAddress(payment.TicketParams.Recipient),
Expand Down Expand Up @@ -380,6 +376,19 @@
return len(orchs) > 0, nil
}

func (orch *orchestrator) setFixedPricePerSession(sender ethcommon.Address, manifestID ManifestID, priceInfoRat *big.Rat) {
if orch.node.Balances == nil {
glog.Warning("Node balances are not initialized")
return
}
if balances, ok := orch.node.Balances.balances[sender]; ok {
if balances.FixedPrice(manifestID) == nil {
balances.SetFixedPrice(manifestID, priceInfoRat)
glog.V(6).Infof("Setting fixed price=%v for session=%v", priceInfoRat, manifestID)
}

Check warning on line 388 in core/orchestrator.go

View check run for this annotation

Codecov / codecov/patch

core/orchestrator.go#L385-L388

Added lines #L385 - L388 were not covered by tests
}
}

func NewOrchestrator(n *LivepeerNode, rm common.RoundsManager) *orchestrator {
var addr ethcommon.Address
if n.Eth != nil {
Expand Down
Loading