diff --git a/protocol/lavasession/consumer_session_manager.go b/protocol/lavasession/consumer_session_manager.go index 53f6531900..7c06c50bf3 100644 --- a/protocol/lavasession/consumer_session_manager.go +++ b/protocol/lavasession/consumer_session_manager.go @@ -113,7 +113,7 @@ func (csm *ConsumerSessionManager) UpdateAllProviders(epoch uint64, pairingList } csm.setValidAddressesToDefaultValue("", nil) // the starting point is that valid addresses are equal to pairing addresses. // reset session related metrics - csm.consumerMetricsManager.ResetSessionRelatedMetrics() + go csm.consumerMetricsManager.ResetSessionRelatedMetrics() go csm.providerOptimizer.UpdateWeights(CalcWeightsByStake(pairingList), epoch) utils.LavaFormatDebug("updated providers", utils.Attribute{Key: "epoch", Value: epoch}, utils.Attribute{Key: "spec", Value: csm.rpcEndpoint.Key()}) diff --git a/protocol/provideroptimizer/selection_weight.go b/protocol/provideroptimizer/selection_weight.go index e0fdc30f38..f391f5ef91 100644 --- a/protocol/provideroptimizer/selection_weight.go +++ b/protocol/provideroptimizer/selection_weight.go @@ -28,6 +28,11 @@ func NewSelectionWeighter() SelectionWeighter { func (sw *selectionWeighterInst) Weight(address string) int64 { sw.lock.RLock() defer sw.lock.RUnlock() + return sw.weightInner(address) +} + +// assumes lock is held +func (sw *selectionWeighterInst) weightInner(address string) int64 { weight, ok := sw.weights[address] if !ok { // default weight is 1 @@ -52,12 +57,12 @@ func (sw *selectionWeighterInst) WeightedChoice(entries []Entry) string { defer sw.lock.RUnlock() totalWeight := int64(0) for _, entry := range entries { - totalWeight += int64(float64(sw.Weight(entry.Address)) * entry.Part) + totalWeight += int64(float64(sw.weightInner(entry.Address)) * entry.Part) } randWeight := rand.Int63n(totalWeight) currentWeight := int64(0) for _, entry := range entries { - currentWeight += int64(float64(sw.Weight(entry.Address)) * entry.Part) + currentWeight += int64(float64(sw.weightInner(entry.Address)) * entry.Part) if currentWeight > randWeight { return entry.Address }