From 03b64fb4dc621fce1921581ef5e6df975c54b91b Mon Sep 17 00:00:00 2001 From: Elite Encoder Date: Mon, 20 May 2024 16:03:32 -0400 Subject: [PATCH] fix(ai): fix runtime error in aiWorker when pricePerUnit is unset (#3059) * Fix nil baseprice when pricePerUnit is unused in aiWorker * fix: fix priceInfo 'nil' error on discovery This commit ensures that when the `transcodePrice` is not set by the AI orchestrator no `nil` error is thrown when a Gateway requests the orchestrators OrchInfo. * fix(ai): fix incorrect transcodePrice condition This commit fixes the check that is performed to check if transcodePrice is set. --------- Co-authored-by: Rick Staa --- core/orchestrator.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/orchestrator.go b/core/orchestrator.go index bbef0e0dc8..c183d335e3 100644 --- a/core/orchestrator.go +++ b/core/orchestrator.go @@ -332,12 +332,13 @@ func (orch *orchestrator) priceInfo(sender ethcommon.Address, manifestID Manifes transcodePrice = orch.node.GetBasePrice("default") } - var basePrice *big.Rat + basePrice := big.NewRat(0, 1) if caps == nil { - basePrice = transcodePrice + if transcodePrice != nil { + basePrice = transcodePrice + } } else { // The base price is the sum of the prices of individual capability + model ID pairs - basePrice = big.NewRat(0, 1) for cap := range caps.Capacities { // If the capability does not have constraints (and thus any model constraints) skip it // because we only price a capability together with a model ID right now @@ -359,7 +360,7 @@ func (orch *orchestrator) priceInfo(sender ethcommon.Address, manifestID Manifes // If no priced capabilities were signaled by the broadcaster assume that they are requesting // transcoding and set the base price to the transcode price - if basePrice.Cmp(big.NewRat(0, 1)) == 0 { + if transcodePrice != nil && basePrice.Cmp(big.NewRat(0, 1)) == 0 { basePrice = transcodePrice } }