-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidator.go
70 lines (59 loc) · 2.27 KB
/
validator.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package collector
import (
"log"
"sort"
"strconv"
"sync"
"github.com/forbole/solana-exporter/types"
)
func (collector *SolanaCollector) CollectValidatorStats() {
voteAccounts, err := collector.SolanaClient.GetVoteAccounts()
if err != nil {
ErrorGauge.WithLabelValues("get_vote_accounts").Inc()
log.Print(err)
}
// Sort to get validator ranking.
sort.Slice(voteAccounts.Current, func(i, j int) bool {
return voteAccounts.Current[i].ActivatedStake > voteAccounts.Current[j].ActivatedStake
})
var stakedTotal uint64
for index, account := range voteAccounts.Current {
stakedTotal += account.ActivatedStake
if _, ok := collector.ValidatorAddresses[account.VotePubkey]; ok {
ValidatorCommission.WithLabelValues(account.VotePubkey).Set(float64(account.Commission))
ValidatorStaked.WithLabelValues(account.VotePubkey).Set(types.ConvertLamportToSolana(account.ActivatedStake))
ValidatorStakedRanking.WithLabelValues(account.VotePubkey).Set(float64(index + 1))
// Reward handler
for _, credits := range account.EpochCredits {
// epochCredits: <array> [epoch, credits, previousCredits]
epoch := credits[0]
earnedCedit := credits[1] - credits[2]
ValidatorEpochCredits.WithLabelValues(account.VotePubkey, strconv.Itoa(epoch)).Set(float64(earnedCedit))
}
}
}
Stakedtotal.WithLabelValues().Set(types.ConvertLamportToSolana(stakedTotal))
var wg sync.WaitGroup
for address := range collector.ValidatorAddresses {
wg.Add(1)
go func(address string) {
defer wg.Done()
if rewards, err := collector.SolanaClient.GetInflationReward(address); err != nil {
ErrorGauge.WithLabelValues("get_validator_inflation_reward").Inc()
log.Print(err)
} else {
for _, reward := range rewards {
ValidatorInflationRewardCurrentEpoch.WithLabelValues(address).Set(types.ConvertLamportToSolana(reward.Amount))
ValidatorInflationReward.WithLabelValues(address, strconv.FormatUint(reward.Epoch, 10)).Set(types.ConvertLamportToSolana(reward.Amount))
}
}
if delegators, err := collector.SolanaClient.GetDelegatorsCount(address); err != nil {
ErrorGauge.WithLabelValues("get_delegators_count").Inc()
log.Print(err)
} else {
ValidatorDelegatorCount.WithLabelValues(address).Set(float64(len(delegators)))
}
}(address)
}
wg.Wait()
}