provideroptimizer

package
v5.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheMaxCost             = 20000 // each item cost would be 1
	CacheNumCounters         = 20000 // expect 2000 items
	DefaultExplorationChance = 0.1
	CostExplorationChance    = 0.01
)

Variables

View Source
var (
	OptimizerNumTiers = 4
	MinimumEntries    = 5
	ATierChance       = 0.75
	LastTierChance    = 0.0
	AutoAdjustTiers   = false
)

Functions

func CumulativeProbabilityFunctionForPoissonDist

func CumulativeProbabilityFunctionForPoissonDist(k_events uint64, lambda float64) float64

func PrintTierChances

func PrintTierChances(tierChances map[int]float64) string

Types

type ConcurrentBlockStore

type ConcurrentBlockStore struct {
	Lock  sync.Mutex
	Time  time.Time
	Block uint64
}

type Entry

type Entry struct {
	Address string
	Score   float64
	Part    float64
}

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 NewProviderOptimizer(strategy Strategy, averageBlockTIme time.Duration, wantedNumProvidersInConcurrency uint, consumerOptimizerQoSClient consumerOptimizerQoSClientInf, chainId string) *ProviderOptimizer

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

func (st *SelectionTierInst) ShiftTierChance(numTiers int, initialTierChances map[int]float64) map[int]float64

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

func (s Strategy) GetStrategyFactor() math.LegacyDec

GetStrategyFactor gets the appropriate factor to multiply the sync factor with according to the strategy

func (Strategy) String

func (s Strategy) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳