From 9d33edd2085687ff6f03934f7502049d101d254e Mon Sep 17 00:00:00 2001 From: Oren Date: Mon, 2 Dec 2024 17:02:15 +0200 Subject: [PATCH] fix tier prints --- .../metrics/consumer_optimizer_qos_client.go | 30 ++++++++++--------- .../provideroptimizer/provider_optimizer.go | 2 +- .../provider_optimizer_refactor.go | 10 ++++++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/protocol/metrics/consumer_optimizer_qos_client.go b/protocol/metrics/consumer_optimizer_qos_client.go index 895745baea..985e6895ca 100644 --- a/protocol/metrics/consumer_optimizer_qos_client.go +++ b/protocol/metrics/consumer_optimizer_qos_client.go @@ -41,23 +41,23 @@ type OptimizerQoSReport struct { LatencyScore float64 GenericScore float64 EntryIndex int - TierChances map[int]float64 + TierChances string } type optimizerQoSReportToSend struct { - Timestamp time.Time `json:"timestamp"` - SyncScore float64 `json:"sync_score"` - AvailabilityScore float64 `json:"availability_score"` - LatencyScore float64 `json:"latency_score"` - GenericScore float64 `json:"generic_score"` - ProviderAddress string `json:"provider"` - ConsumerOrigin string `json:"consumer"` - ChainId string `json:"chain_id"` - NodeErrorRate float64 `json:"node_error_rate"` - Epoch uint64 `json:"epoch"` - ProviderStake int64 `json:"provider_stake"` - EntryIndex int `json:"entry_index"` - TierChances map[int]float64 `json:"tier_chances"` + Timestamp time.Time `json:"timestamp"` + SyncScore float64 `json:"sync_score"` + AvailabilityScore float64 `json:"availability_score"` + LatencyScore float64 `json:"latency_score"` + GenericScore float64 `json:"generic_score"` + ProviderAddress string `json:"provider"` + ConsumerOrigin string `json:"consumer"` + ChainId string `json:"chain_id"` + NodeErrorRate float64 `json:"node_error_rate"` + Epoch uint64 `json:"epoch"` + ProviderStake int64 `json:"provider_stake"` + EntryIndex int `json:"entry_index"` + TierChances string `json:"tier_chances"` } func (oqosr optimizerQoSReportToSend) String() string { @@ -148,6 +148,7 @@ func (coqc *ConsumerOptimizerQoSClient) appendOptimizerQoSReport(report *Optimiz Epoch: epoch, NodeErrorRate: coqc.calculateNodeErrorRate(chainId, report.ProviderAddress), ProviderStake: coqc.getProviderChainStake(chainId, report.ProviderAddress, epoch), + TierChances: report.TierChances, } coqc.queueSender.appendQueue(optimizerQoSReportToSend) @@ -169,6 +170,7 @@ func (coqc *ConsumerOptimizerQoSClient) appendOptimizerQoSReportRefactored(repor Epoch: epoch, NodeErrorRate: coqc.calculateNodeErrorRate(chainId, report.ProviderAddress), ProviderStake: coqc.getProviderChainStake(chainId, report.ProviderAddress, epoch), + TierChances: report.TierChances, } coqc.queueSenderRefactored.appendQueue(optimizerQoSReportToSend) diff --git a/protocol/provideroptimizer/provider_optimizer.go b/protocol/provideroptimizer/provider_optimizer.go index 672c62f293..8898f167a6 100644 --- a/protocol/provideroptimizer/provider_optimizer.go +++ b/protocol/provideroptimizer/provider_optimizer.go @@ -206,7 +206,7 @@ func (po *ProviderOptimizer) CalculateQoSScoresForMetrics(allAddresses []string, for idx, entry := range rawScores { qosReport := providersScores[entry.Address] qosReport.EntryIndex = idx - qosReport.TierChances = tierChances + qosReport.TierChances = PrintTierChances(tierChances) reports = append(reports, qosReport) } diff --git a/protocol/provideroptimizer/provider_optimizer_refactor.go b/protocol/provideroptimizer/provider_optimizer_refactor.go index db666fc9df..baf0d2be50 100644 --- a/protocol/provideroptimizer/provider_optimizer_refactor.go +++ b/protocol/provideroptimizer/provider_optimizer_refactor.go @@ -173,13 +173,21 @@ func (po *ProviderOptimizer_Refactor) CalculateQoSScoresForMetrics(allAddresses for idx, entry := range rawScores { qosReport := providersScores[entry.Address] qosReport.EntryIndex = idx - qosReport.TierChances = tierChances + qosReport.TierChances = PrintTierChances(tierChances) reports = append(reports, qosReport) } return reports } +func PrintTierChances(tierChances map[int]float64) string { + var tierChancesString string + for tier, chance := range tierChances { + tierChancesString += fmt.Sprintf("%d: %f, ", tier, chance) + } + return tierChancesString +} + func (po *ProviderOptimizer_Refactor) CalculateSelectionTiers_Refactor(allAddresses []string, ignoredProviders map[string]struct{}, cu uint64, requestedBlock int64) (SelectionTier, Exploration_Refactor, map[string]*metrics.OptimizerQoSReport) { explorationCandidate := Exploration_Refactor{address: "", time: time.Now().Add(time.Hour)} selectionTier := NewSelectionTier()