-
Notifications
You must be signed in to change notification settings - Fork 200
/
pairing_score.go
55 lines (48 loc) · 1.63 KB
/
pairing_score.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package scores
import (
"cosmossdk.io/math"
epochstoragetypes "github.com/lavanet/lava/x/epochstorage/types"
pairingtypes "github.com/lavanet/lava/x/pairing/types"
)
const (
// TODO: temp strategy weight until we implement taking it out of the policy
UNIFORM_WEIGHT uint64 = 1
)
// PairingScore holds a provider's score with respect to a set of requirements (ScoreReq), indexed by their unique name.
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
}
func (ps *PairingScore) IsValidForSelection(slotIndex int) bool {
if ps.SkipForSelection {
return false
}
_, ok := ps.SlotFiltering[slotIndex]
// invalid if provider has mix filtering for this slot index
return !ok
}
func (ps *PairingScore) InvalidIndexes(possibleIndexes []int) []int {
invalidIndexes := []int{}
for _, slotIndex := range possibleIndexes {
if _, ok := ps.SlotFiltering[slotIndex]; ok {
invalidIndexes = append(invalidIndexes, slotIndex)
}
}
return invalidIndexes
}
func NewPairingScore(stakeEntry *epochstoragetypes.StakeEntry, qos pairingtypes.QualityOfServiceReport) *PairingScore {
score := PairingScore{
Provider: stakeEntry,
Score: math.OneUint(),
ScoreComponents: map[string]math.Uint{},
SkipForSelection: false,
QosExcellenceReport: qos,
}
return &score
}
// map: key: ScoreReq name, value: weight in the final pairing score
type ScoreStrategy map[string]uint64