Documentation ¶
Index ¶
- Constants
- Variables
- func AddProviderToSelection(providerScore *PairingScore, groupIndexes []int, totalScore math.Uint, ...) (math.Uint, map[int]math.Uint)
- func CalcGeoCost(reqGeo planstypes.Geolocation, providerGeos []planstypes.Geolocation) (minLatencyGeo planstypes.Geolocation, minLatencyCost math.Uint)
- func CalcGeoLatency(reqGeo planstypes.Geolocation, providerGeos []planstypes.Geolocation) (planstypes.Geolocation, uint64)
- func CalcPairingScore(scores []*PairingScore, strategy ScoreStrategy, diffSlot PairingSlotInf) error
- func CalculateTotalScoresForGroup(scores []*PairingScore, groupIndexes []int) (totalScore math.Uint, slotIndexScore map[int]math.Uint, err error)
- func PickProviders(ctx sdk.Context, scores []*PairingScore, groupIndexes []int, hashData []byte) (returnedProviders []epochstoragetypes.StakeEntry)
- func PrepareHashData(projectIndex, chainID string, epochHash []byte, idx int) []byte
- func RemoveProviderFromSelection(providerScore *PairingScore, groupIndexes []int, totalScore math.Uint, ...) (math.Uint, map[int]math.Uint)
- type GeoReq
- type PairingScore
- type PairingSlot
- type PairingSlotGroup
- type PairingSlotInf
- type QosGetter
- type QosReq
- type ScoreReq
- type ScoreStrategy
- type StakeReq
Constants ¶
const ( // TODO: temp strategy weight until we implement taking it out of the policy UNIFORM_WEIGHT uint64 = 1 )
Variables ¶
var GEO_LATENCY_MAP = map[planstypes.Geolocation]map[planstypes.Geolocation]uint64{ planstypes.Geolocation_AS: { planstypes.Geolocation_AU: 146, planstypes.Geolocation_EU: 155, }, planstypes.Geolocation_USE: { planstypes.Geolocation_USC: 42, planstypes.Geolocation_USW: 68, planstypes.Geolocation_EU: 116, }, planstypes.Geolocation_USW: { planstypes.Geolocation_USC: 45, planstypes.Geolocation_USE: 68, }, planstypes.Geolocation_USC: { planstypes.Geolocation_USE: 42, planstypes.Geolocation_USW: 45, planstypes.Geolocation_EU: 170, }, planstypes.Geolocation_EU: { planstypes.Geolocation_USE: 116, planstypes.Geolocation_AF: 138, planstypes.Geolocation_AS: 155, planstypes.Geolocation_USC: 170, }, planstypes.Geolocation_AF: { planstypes.Geolocation_EU: 138, planstypes.Geolocation_USE: 203, planstypes.Geolocation_AS: 263, }, planstypes.Geolocation_AU: { planstypes.Geolocation_AS: 146, planstypes.Geolocation_USW: 179, }, }
GEO_LATENCY_MAP is a map of lists of GeoLatency that defines the cost of geo mismatch for each single geolocation. The map key is a single geolocation and the value is an ordered list of neighbors and their latency (ordered by latency) latency data from: https://wondernetwork.com/pings (July 2023)
Functions ¶
func AddProviderToSelection ¶
func CalcGeoCost ¶
func CalcGeoCost(reqGeo planstypes.Geolocation, providerGeos []planstypes.Geolocation) (minLatencyGeo planstypes.Geolocation, minLatencyCost math.Uint)
CalcGeoCost() finds the minimal latency between the required geo and the provider's supported geolocations
func CalcGeoLatency ¶
func CalcGeoLatency(reqGeo planstypes.Geolocation, providerGeos []planstypes.Geolocation) (planstypes.Geolocation, uint64)
func CalcPairingScore ¶
func CalcPairingScore(scores []*PairingScore, strategy ScoreStrategy, diffSlot PairingSlotInf) error
CalcPairingScore calculates the final pairing score for a pairing slot (with strategy) For efficiency purposes, we calculate the score on a diff slot which represents the diff reqs of the current slot and the previous slot
func CalculateTotalScoresForGroup ¶
func CalculateTotalScoresForGroup(scores []*PairingScore, groupIndexes []int) (totalScore math.Uint, slotIndexScore map[int]math.Uint, err error)
this function calculates the total score, and negative score modifiers for each slot. the negative score modifiers contain the total stake of providers that are not allowed so if a provider is not allowed in slot X, it will be added to the total score but will have slotIndexScore[X]+= providerStake and during the selection of slot X we will have the selection effective sum as: totalScore - slotIndexScore[X], and that provider that is not allowed can't be selected
func PickProviders ¶
func PickProviders(ctx sdk.Context, scores []*PairingScore, groupIndexes []int, hashData []byte) (returnedProviders []epochstoragetypes.StakeEntry)
PickProviders pick a <group-count> providers set with a pseudo-random weighted choice (using the providers' score list and hashData) selection is done by adding all of the scores in the sorted list and generating a random value
func PrepareHashData ¶
PrepareHashData prepares the hash needed in the pseudo-random choice of providers
Types ¶
type GeoReq ¶
type GeoReq struct {
Geo int32
}
geo requirement that implements the ScoreReq interface
func (GeoReq) GetReqForSlot ¶
func (gr GeoReq) GetReqForSlot(policy planstypes.Policy, slotIdx int) ScoreReq
TODO: this function doesn't return the optimal geo reqs for the case that there are more required geos than providers to pair
type PairingScore ¶
type PairingScore struct { Provider *epochstoragetypes.StakeEntry Score math.Uint ScoreComponents map[string]math.Uint SkipForSelection bool SlotFiltering map[int]struct{} // slot indexes here are skipped QosExcellenceReport pairingtypes.QualityOfServiceReport }
PairingScore holds a provider's score with respect to a set of requirements (ScoreReq), indexed by their unique name.
func NewPairingScore ¶
func NewPairingScore(stakeEntry *epochstoragetypes.StakeEntry, qos pairingtypes.QualityOfServiceReport) *PairingScore
func (*PairingScore) InvalidIndexes ¶
func (ps *PairingScore) InvalidIndexes(possibleIndexes []int) []int
func (*PairingScore) IsValidForSelection ¶
func (ps *PairingScore) IsValidForSelection(slotIndex int) bool
type PairingSlot ¶
func CalcSlots ¶
func CalcSlots(policy *planstypes.Policy) []*PairingSlot
get the overall requirements from the policy and assign slots that'll fulfil them
func NewPairingSlot ¶
func NewPairingSlot(slotIndex int) *PairingSlot
func (PairingSlot) Equal ¶
func (s PairingSlot) Equal(other PairingSlotInf) bool
func (PairingSlot) Requirements ¶
func (s PairingSlot) Requirements() map[string]ScoreReq
type PairingSlotGroup ¶
func NewPairingSlotGroup ¶
func NewPairingSlotGroup(pairingSlot *PairingSlot) *PairingSlotGroup
func (*PairingSlotGroup) AddToGroup ¶
func (psg *PairingSlotGroup) AddToGroup(pairingSlot *PairingSlot)
func (PairingSlotGroup) Indexes ¶
func (s PairingSlotGroup) Indexes() []int
func (PairingSlotGroup) Requirements ¶
func (s PairingSlotGroup) Requirements() map[string]ScoreReq
func (PairingSlotGroup) Subtract ¶
func (psg PairingSlotGroup) Subtract(other *PairingSlotGroup) *PairingSlot
Subtract generates a diff slot that contains the reqs that are in the slot receiver but not in the "other" slot
type PairingSlotInf ¶
type QosGetter ¶
type QosGetter interface {
GetQos(ctx sdk.Context, chainID string, cluster string, provider string) (pairingtypes.QualityOfServiceReport, error)
}
type QosReq ¶
type QosReq struct{}
QosReq implements the ScoreReq interface for provider staking requirement(s)
func (QosReq) Equal ¶
Equal used to compare slots to determine slot groups. Equal always returns true (there are no different "types" of qos)
func (QosReq) GetReqForSlot ¶
func (qr QosReq) GetReqForSlot(policy planstypes.Policy, slotIdx int) ScoreReq
type ScoreReq ¶
type ScoreReq interface { // Init() initializes the ScoreReq object and returns whether it's active Init(policy planstypes.Policy) bool // Score() calculates a provider's score according to the requirement Score(score PairingScore) math.Uint // GetName returns the unique name of the ScoreReq implementation GetName() string // Equal compares two ScoreReq objects Equal(other ScoreReq) bool // GetReqForSlot gets ScoreReq for slot by its index GetReqForSlot(policy planstypes.Policy, slotIdx int) ScoreReq }
ScoreReq is an interface for pairing requirement scoring
func GetAllReqs ¶
func GetAllReqs() []ScoreReq
type ScoreStrategy ¶
map: key: ScoreReq name, value: weight in the final pairing score
func GetStrategy ¶
func GetStrategy() ScoreStrategy
TODO: currently we'll use weight=1 for all reqs. In the future, we'll get it from policy
type StakeReq ¶
type StakeReq struct{}
StakeReq implements the ScoreReq interface for provider staking requirement(s)
func (*StakeReq) Equal ¶
Equal used to compare slots to determine slot groups. Equal always returns true (StakeReq score of an entry is the entry's stake)
func (*StakeReq) GetReqForSlot ¶
func (sr *StakeReq) GetReqForSlot(policy planstypes.Policy, slotIdx int) ScoreReq