Documentation
¶
Index ¶
- Constants
- Variables
- func CumulativeProbabilityFunctionForPoissonDist(k_events uint64, lambda float64) float64
- func PrintTierChances(tierChances map[int]float64) string
- type ConcurrentBlockStore
- type Entry
- type Exploration
- type ProviderData
- type ProviderOptimizer
- func (po *ProviderOptimizer) AppendProbeRelayData(providerAddress string, latency time.Duration, success bool)
- func (po *ProviderOptimizer) AppendRelayData(provider string, latency time.Duration, cu, syncBlock uint64)
- func (po *ProviderOptimizer) AppendRelayFailure(provider string)
- func (po *ProviderOptimizer) CalculateProbabilityOfBlockError(requestedBlock int64, providerData ProviderData) sdk.Dec
- func (po *ProviderOptimizer) CalculateQoSScoresForMetrics(allAddresses []string, ignoredProviders map[string]struct{}, cu uint64, ...) []*metrics.OptimizerQoSReport
- func (po *ProviderOptimizer) CalculateSelectionTiers(allAddresses []string, ignoredProviders map[string]struct{}, cu uint64, ...) (SelectionTier, Exploration, map[string]*metrics.OptimizerQoSReport)
- func (po *ProviderOptimizer) ChooseProvider(allAddresses []string, ignoredProviders map[string]struct{}, cu uint64, ...) (addresses []string, tier int)
- func (po *ProviderOptimizer) GetMinTierEntries(selectionTier SelectionTier, selectionTierScoresCount int) int
- func (po *ProviderOptimizer) GetNumTiersWanted(selectionTier SelectionTier, selectionTierScoresCount int) int
- func (po *ProviderOptimizer) GetProviderTier(providerAddress string, selectionTier SelectionTier) int
- func (po *ProviderOptimizer) GetReputationReportForProvider(providerAddress string) (report *pairingtypes.QualityOfServiceReport, lastUpdateTime time.Time)
- func (po *ProviderOptimizer) Strategy() Strategy
- func (po *ProviderOptimizer) UpdateWeights(weights map[string]int64, epoch uint64)
- type SelectionTier
- type SelectionTierInst
- func (st *SelectionTierInst) AddScore(entry string, score float64)
- func (st *SelectionTierInst) GetRawScores() []Entry
- func (st *SelectionTierInst) GetTier(tier int, numTiers int, minimumEntries int) []Entry
- func (st *SelectionTierInst) ScoresCount() int
- func (st *SelectionTierInst) SelectTierRandomly(numTiers int, tierChances map[int]float64) int
- func (st *SelectionTierInst) ShiftTierChance(numTiers int, initialTierChances map[int]float64) map[int]float64
- type SelectionWeighter
- type Strategy
Constants ¶
const ( CacheMaxCost = 20000 // each item cost would be 1 CacheNumCounters = 20000 // expect 2000 items DefaultExplorationChance = 0.1 CostExplorationChance = 0.01 )
Variables ¶
var ( OptimizerNumTiers = 4 MinimumEntries = 5 ATierChance = 0.75 LastTierChance = 0.0 AutoAdjustTiers = false )
Functions ¶
func PrintTierChances ¶
Types ¶
type ConcurrentBlockStore ¶
type Exploration ¶
type Exploration struct {
// contains filtered or unexported fields
}
The exploration mechanism makes the optimizer return providers that were not talking to the consumer for a long time (a couple of seconds). This allows better distribution of paired providers by avoiding returning the same best providers over and over. The Exploration struct holds a provider address and last QoS metrics update time (ScoreStore)
type ProviderData ¶
type ProviderData struct { Availability score.ScoreStorer // will be used to calculate the probability of error Latency score.ScoreStorer // will be used to calculate the latency score Sync score.ScoreStorer // will be used to calculate the sync score for spectypes.LATEST_BLOCK/spectypes.NOT_APPLICABLE requests SyncBlock uint64 // will be used to calculate the probability of block error }
type ProviderOptimizer ¶
type ProviderOptimizer struct { OptimizerNumTiers int // number of tiers to use OptimizerMinTierEntries int // minimum number of entries in a tier to be considered for selection // contains filtered or unexported fields }
func NewProviderOptimizer ¶
func (*ProviderOptimizer) AppendProbeRelayData ¶
func (po *ProviderOptimizer) AppendProbeRelayData(providerAddress string, latency time.Duration, success bool)
AppendProbeRelayData updates a provider's QoS metrics for a probe relay message
func (*ProviderOptimizer) AppendRelayData ¶
func (po *ProviderOptimizer) AppendRelayData(provider string, latency time.Duration, cu, syncBlock uint64)
AppendRelayData updates a provider's QoS metrics for a successful relay
func (*ProviderOptimizer) AppendRelayFailure ¶
func (po *ProviderOptimizer) AppendRelayFailure(provider string)
AppendRelayFailure updates a provider's QoS metrics for a failed relay
func (*ProviderOptimizer) CalculateProbabilityOfBlockError ¶
func (po *ProviderOptimizer) CalculateProbabilityOfBlockError(requestedBlock int64, providerData ProviderData) sdk.Dec
CalculateProbabilityOfBlockError calculates the probability that a provider doesn't a specific requested block when the consumer asks the optimizer to fetch a provider with the specific block
func (*ProviderOptimizer) CalculateQoSScoresForMetrics ¶
func (po *ProviderOptimizer) CalculateQoSScoresForMetrics(allAddresses []string, ignoredProviders map[string]struct{}, cu uint64, requestedBlock int64) []*metrics.OptimizerQoSReport
func (*ProviderOptimizer) CalculateSelectionTiers ¶
func (po *ProviderOptimizer) CalculateSelectionTiers(allAddresses []string, ignoredProviders map[string]struct{}, cu uint64, requestedBlock int64) (SelectionTier, Exploration, map[string]*metrics.OptimizerQoSReport)
func (*ProviderOptimizer) ChooseProvider ¶
func (po *ProviderOptimizer) ChooseProvider(allAddresses []string, ignoredProviders map[string]struct{}, cu uint64, requestedBlock int64) (addresses []string, tier int)
returns a sub set of selected providers according to their scores, perturbation factor will be added to each score in order to randomly select providers that are not always on top
func (*ProviderOptimizer) GetMinTierEntries ¶
func (po *ProviderOptimizer) GetMinTierEntries(selectionTier SelectionTier, selectionTierScoresCount int) int
GetMinTierEntries gets minimum number of entries in a tier to be considered for selection if AutoAdjustTiers global is true, the number of providers per tier is divided equally between them
func (*ProviderOptimizer) GetNumTiersWanted ¶
func (po *ProviderOptimizer) GetNumTiersWanted(selectionTier SelectionTier, selectionTierScoresCount int) int
GetNumTiersWanted returns the number of tiers wanted if we have enough providers to create the tiers return the configured number of tiers wanted if not, set the number of tiers to the number of providers we currently have
func (*ProviderOptimizer) GetProviderTier ¶
func (po *ProviderOptimizer) GetProviderTier(providerAddress string, selectionTier SelectionTier) int
func (*ProviderOptimizer) GetReputationReportForProvider ¶
func (po *ProviderOptimizer) GetReputationReportForProvider(providerAddress string) (report *pairingtypes.QualityOfServiceReport, lastUpdateTime time.Time)
func (*ProviderOptimizer) Strategy ¶
func (po *ProviderOptimizer) Strategy() Strategy
func (*ProviderOptimizer) UpdateWeights ¶
func (po *ProviderOptimizer) UpdateWeights(weights map[string]int64, epoch uint64)
UpdateWeights update the selection weighter weights
type SelectionTier ¶
type SelectionTier interface { AddScore(entry string, score float64) GetTier(tier int, numTiers int, minimumEntries int) []Entry SelectTierRandomly(numTiers int, tierChances map[int]float64) int ShiftTierChance(numTiers int, initialTierChances map[int]float64) map[int]float64 ScoresCount() int GetRawScores() []Entry }
selectionTier is a utility to categorize provider addresses based on their relative stakes. This mechanism ensures that providers with similar stakes compete for relays based on their service quality. For example, if there are multiple providers with low stakes but good service, they will compete more directly with each other than with a provider with a high stake but poor service. This helps prevent providers with large stakes from monopolizing relay services.
func NewSelectionTier ¶
func NewSelectionTier() SelectionTier
type SelectionTierInst ¶
type SelectionTierInst struct {
// contains filtered or unexported fields
}
func (*SelectionTierInst) AddScore ¶
func (st *SelectionTierInst) AddScore(entry string, score float64)
func (*SelectionTierInst) GetRawScores ¶
func (st *SelectionTierInst) GetRawScores() []Entry
func (*SelectionTierInst) GetTier ¶
func (st *SelectionTierInst) GetTier(tier int, numTiers int, minimumEntries int) []Entry
func (*SelectionTierInst) ScoresCount ¶
func (st *SelectionTierInst) ScoresCount() int
func (*SelectionTierInst) SelectTierRandomly ¶
func (st *SelectionTierInst) SelectTierRandomly(numTiers int, tierChances map[int]float64) int
func (*SelectionTierInst) ShiftTierChance ¶
type SelectionWeighter ¶
type SelectionWeighter interface { Weight(address string) int64 SetWeights(weights map[string]int64) WeightedChoice(possibilities []Entry) string }
SelectionWeighter is a utility to select an address based on a weight.
func NewSelectionWeighter ¶
func NewSelectionWeighter() SelectionWeighter
type Strategy ¶
type Strategy int
Strategy defines the pairing strategy. Using different strategies allow users to determine the providers type they'll be paired with: providers with low latency, fresh sync and more.
const ( StrategyBalanced Strategy = iota StrategyLatency // prefer low latency StrategySyncFreshness // prefer better sync StrategyCost // prefer low CU cost (minimize optimizer exploration) StrategyPrivacy // prefer pairing with a single provider (not fully implemented) StrategyAccuracy // encourage optimizer exploration (higher cost) StrategyDistributed // prefer pairing with different providers (slightly minimize optimizer exploration) )
func (Strategy) GetStrategyFactor ¶
GetStrategyFactor gets the appropriate factor to multiply the sync factor with according to the strategy