diff --git a/go.mod b/go.mod index f5e67d4..7eb54b1 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.36.0 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/math v1.0.0-beta.2 // indirect + cosmossdk.io/math v1.3.0 // indirect filippo.io/edwards25519 v1.0.0-rc.1 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect @@ -140,6 +140,7 @@ require ( go.opentelemetry.io/otel/metric v1.25.0 // indirect go.opentelemetry.io/proto/otlp v1.1.0 // indirect golang.org/x/crypto v0.21.0 // indirect + golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect golang.org/x/net v0.23.0 // indirect golang.org/x/oauth2 v0.17.0 // indirect golang.org/x/sync v0.6.0 // indirect @@ -157,7 +158,7 @@ require ( gopkg.in/ini.v1 v1.66.6 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - sigs.k8s.io/yaml v1.3.0 // indirect + sigs.k8s.io/yaml v1.4.0 // indirect ) replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 diff --git a/go.sum b/go.sum index b3d795e..8393cf4 100644 --- a/go.sum +++ b/go.sum @@ -74,6 +74,8 @@ cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE= cosmossdk.io/math v1.0.0-beta.2 h1:17hSVc9ne1c31IaLDfjRojtN+y4Rd2N8H/6Fht2sBzw= cosmossdk.io/math v1.0.0-beta.2/go.mod h1:u/MXvf8wbUbCsAEyQSSYXXMsczAsFX48e2D6JI86T4o= +cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= +cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= @@ -493,6 +495,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= @@ -1280,6 +1283,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= +golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o= +golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= @@ -1953,3 +1958,4 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/pkg/generators/active_set_tokens.go b/pkg/generators/active_set_tokens.go index f833079..6d6804a 100644 --- a/pkg/generators/active_set_tokens.go +++ b/pkg/generators/active_set_tokens.go @@ -58,10 +58,10 @@ func (g *ActiveSetTokensGenerator) Generate(state *statePkg.State) []prometheus. }) sort.Slice(activeValidators, func(i, j int) bool { - return utils.StrToFloat64(activeValidators[i].DelegatorShares) > utils.StrToFloat64(activeValidators[j].DelegatorShares) + return activeValidators[i].DelegatorShares.GT(activeValidators[j].DelegatorShares) }) - lastValidatorStake := utils.StrToFloat64(activeValidators[len(activeValidators)-1].DelegatorShares) + lastValidatorStake := activeValidators[len(activeValidators)-1].DelegatorShares.MustFloat64() if chainStakingParams != nil && len(activeValidators) >= chainStakingParams.StakingParams.MaxValidators { activeSetTokensGauge.With(prometheus.Labels{ diff --git a/pkg/generators/single_validator_info.go b/pkg/generators/single_validator_info.go index cb534b3..2d55b20 100644 --- a/pkg/generators/single_validator_info.go +++ b/pkg/generators/single_validator_info.go @@ -157,22 +157,22 @@ func (g *SingleValidatorInfoGenerator) Generate(state *statePkg.State) []prometh commissionGauge.With(prometheus.Labels{ "chain": chain.Name, "address": validatorAddr.Address, - }).Set(utils.StrToFloat64(validator.Commission.CommissionRates.Rate)) + }).Set(validator.Commission.CommissionRates.Rate.MustFloat64()) commissionMaxGauge.With(prometheus.Labels{ "chain": chain.Name, "address": validatorAddr.Address, - }).Set(utils.StrToFloat64(validator.Commission.CommissionRates.MaxRate)) + }).Set(validator.Commission.CommissionRates.MaxRate.MustFloat64()) commissionMaxChangeGauge.With(prometheus.Labels{ "chain": chain.Name, "address": validatorAddr.Address, - }).Set(utils.StrToFloat64(validator.Commission.CommissionRates.MaxChangeRate)) + }).Set(validator.Commission.CommissionRates.MaxChangeRate.MustFloat64()) delegationsGauge.With(prometheus.Labels{ "chain": chain.Name, "address": validatorAddr.Address, - }).Set(utils.StrToFloat64(validator.DelegatorShares)) + }).Set(validator.DelegatorShares.MustFloat64()) } } diff --git a/pkg/generators/validator_rank.go b/pkg/generators/validator_rank.go index ef68c87..8e67fc2 100644 --- a/pkg/generators/validator_rank.go +++ b/pkg/generators/validator_rank.go @@ -82,7 +82,7 @@ func (g *ValidatorRankGenerator) Generate(state *statePkg.State) []prometheus.Co }) sort.Slice(activeValidators, func(i, j int) bool { - return utils.StrToFloat64(activeValidators[i].DelegatorShares) > utils.StrToFloat64(activeValidators[j].DelegatorShares) + return activeValidators[i].DelegatorShares.GT(activeValidators[j].DelegatorShares) }) rank, found := utils.FindIndex(activeValidators, func(v types.Validator) bool { diff --git a/pkg/generators/validators_info.go b/pkg/generators/validators_info.go index 597df92..a02aa02 100644 --- a/pkg/generators/validators_info.go +++ b/pkg/generators/validators_info.go @@ -1,6 +1,7 @@ package generators import ( + "cosmossdk.io/math" "main/pkg/constants" fetchersPkg "main/pkg/fetchers" statePkg "main/pkg/state" @@ -54,13 +55,13 @@ func (g *ValidatorsInfoGenerator) Generate(state *statePkg.State) []prometheus.C }) sort.Slice(activeValidators, func(i, j int) bool { - return utils.StrToFloat64(activeValidators[i].DelegatorShares) > utils.StrToFloat64(activeValidators[j].DelegatorShares) + return activeValidators[i].DelegatorShares.GT(activeValidators[j].DelegatorShares) }) - var totalStake float64 = 0 + totalStake := math.LegacyNewDec(0) for _, activeValidator := range activeValidators { - totalStake += utils.StrToFloat64(activeValidator.DelegatorShares) + totalStake = totalStake.Add(activeValidator.DelegatorShares) } validatorsCountGauge.With(prometheus.Labels{ @@ -69,7 +70,7 @@ func (g *ValidatorsInfoGenerator) Generate(state *statePkg.State) []prometheus.C totalBondedTokensGauge.With(prometheus.Labels{ "chain": chain, - }).Set(totalStake) + }).Set(totalStake.MustFloat64()) } for chain, validators := range consumersData.Validators { diff --git a/pkg/types/tendermint.go b/pkg/types/tendermint.go index 7e4fe63..2ac7904 100644 --- a/pkg/types/tendermint.go +++ b/pkg/types/tendermint.go @@ -19,7 +19,7 @@ type Validator struct { Jailed bool `json:"jailed"` Status string `json:"status"` Tokens string `json:"tokens"` - DelegatorShares string `json:"delegator_shares"` + DelegatorShares math.LegacyDec `json:"delegator_shares"` Description struct { Moniker string `json:"moniker"` Identity string `json:"identity"` @@ -31,9 +31,9 @@ type Validator struct { UnbondingTime time.Time `json:"unbonding_time"` Commission struct { CommissionRates struct { - Rate string `json:"rate"` - MaxRate string `json:"max_rate"` - MaxChangeRate string `json:"max_change_rate"` + Rate math.LegacyDec `json:"rate"` + MaxRate math.LegacyDec `json:"max_rate"` + MaxChangeRate math.LegacyDec `json:"max_change_rate"` } `json:"commission_rates"` UpdateTime time.Time `json:"update_time"` } `json:"commission"`