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 2 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
29 changes: 17 additions & 12 deletions core/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,17 @@ func (orch *orchestrator) ProcessPayment(ctx context.Context, payment net.Paymen
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 @@ func (orch *orchestrator) ProcessPayment(ctx context.Context, payment net.Paymen
}

// 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,15 @@ func (orch *orchestrator) isActive(addr ethcommon.Address) (bool, error) {
return len(orchs) > 0, nil
}

func (orch *orchestrator) setFixedPricePerSession(sender ethcommon.Address, manifestID ManifestID, priceInfoRat *big.Rat) {
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)
}
}
}

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