From 023e37f4704abb269fc8ba06fc95a69e53b059dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Leszko?= Date: Tue, 31 Oct 2023 16:18:55 +0100 Subject: [PATCH 1/3] Fix setting fixed price per session with initial price 0 --- core/orchestrator.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/core/orchestrator.go b/core/orchestrator.go index 9b1a7c77e6..3f08e5d7f5 100644 --- a/core/orchestrator.go +++ b/core/orchestrator.go @@ -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 { @@ -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), @@ -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 { From 6ad8b85ac9171ee6af39d04c648d6b5fa4efb5b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Leszko?= Date: Tue, 31 Oct 2023 16:20:16 +0100 Subject: [PATCH 2/3] Fix setting fixed price per session with initial price 0 --- core/orchestrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/orchestrator.go b/core/orchestrator.go index 3f08e5d7f5..0a898cdfd7 100644 --- a/core/orchestrator.go +++ b/core/orchestrator.go @@ -108,7 +108,7 @@ func (orch *orchestrator) ProcessPayment(ctx context.Context, payment net.Paymen return nil } - if (payment.Sender == nil || len(payment.Sender) == 0) && payment.TicketParams == nil { + 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) From 93a5bd3e22f4a8a5cf819a7c2b5087f965daf50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Leszko?= Date: Thu, 2 Nov 2023 09:23:47 +0100 Subject: [PATCH 3/3] Fix unit tests --- core/orchestrator.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/orchestrator.go b/core/orchestrator.go index 0a898cdfd7..4430bfcbdb 100644 --- a/core/orchestrator.go +++ b/core/orchestrator.go @@ -377,6 +377,10 @@ func (orch *orchestrator) isActive(addr ethcommon.Address) (bool, error) { } 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)