Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Chains where Bonded Validators > Active Validators #27

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (

var GetConspubMonikerMapWrapper = GetConspubMonikerMap

const activeSetSize = 180

func GetConspubMonikerMap() map[string]string {
var v types.RpcValidators
var vResult map[string]string = make(map[string]string)
Expand All @@ -39,13 +37,42 @@ func GetConspubMonikerMap() map[string]string {
return tokensI > tokensJ
})

activeValidators := v.Validators
if len(activeValidators) > activeSetSize {
activeValidators = activeValidators[:activeSetSize]
bondedValidators := v.Validators
stakingParams := GetStakingParams()

/*
* This logic only applies to chains (e.g. the Cosmos Hub) where
* a validator can be bonded but inactive (e.g. not signing blocks)
* e.g. max_validators=200 but only the top 180 are active
*
* For most other chains, if a validator is bonded, they are active
*/

// TO-DO replace MaxValidators here with active validators
if len(bondedValidators) > stakingParams.Params.MaxValidators {
bondedValidators = bondedValidators[:stakingParams.Params.MaxValidators]
}

for _, validator := range activeValidators {
for _, validator := range bondedValidators {
vResult[validator.ConsPubKey.Key] = validator.Description.Moniker
}
return vResult
}

func GetStakingParams() types.StakingParams {
route := GetStakingParamsRoute()
res, err := utils.HttpQuery(constants.RESTAddr + route)
if err != nil {
zap.L().Fatal("Connection to REST failed", zap.Bool("Success", false), zap.String("err:", err.Error()))
return types.StakingParams{}
}

var stakingParams types.StakingParams
err = json.Unmarshal(res, &stakingParams)
if err != nil {
zap.L().Fatal("Failed to unmarshal response", zap.Bool("Success", false), zap.String("err:", err.Error()))
return types.StakingParams{}
}

return stakingParams
}
4 changes: 4 additions & 0 deletions rest/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func GetUpgradeCurrentPlanRoute(cfg config.Config) string {
return "/cosmos/upgrade/v1beta1/current_plan"
}

func GetStakingParamsRoute() string {
return "/cosmos/staking/v1beta1/params"
}

/***********************
* IBC Routes
************************/
Expand Down
12 changes: 12 additions & 0 deletions types/staking_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package types

type StakingParams struct {
Params struct {
UnbondingTime string `json:"unbonding_time"`
MaxValidators int `json:"max_validators"`
MaxEntries int `json:"max_entries"`
HistoricalEntries int `json:"historical_entries"`
BondDenom string `json:"bond_denom"`
MinCommissionRate string `json:"min_commission_rate"`
} `json:"params"`
}
Loading