Skip to content

Commit

Permalink
fix: sort validators by tokens, not by delegator_shares (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno authored Dec 1, 2024
1 parent dda85f0 commit aa542a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/generators/validator_rank.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (g *ValidatorRankGenerator) Generate(state *statePkg.State) []prometheus.Co
})

sort.Slice(activeValidators, func(i, j int) bool {
return activeValidators[i].DelegatorShares.GT(activeValidators[j].DelegatorShares)
return activeValidators[i].Tokens.GT(activeValidators[j].Tokens)
})

rank, found := utils.FindIndex(activeValidators, func(v types.Validator) bool {
Expand Down
18 changes: 9 additions & 9 deletions pkg/generators/validator_rank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func TestValidatorRankGeneratorNotFound(t *testing.T) {
Validators: map[string]*types.ValidatorsResponse{
"chain": {
Validators: []types.Validator{
{DelegatorShares: math.LegacyMustNewDecFromStr("2"), OperatorAddress: "first"},
{DelegatorShares: math.LegacyMustNewDecFromStr("1"), OperatorAddress: "second"},
{DelegatorShares: math.LegacyMustNewDecFromStr("3"), OperatorAddress: "third"},
{Tokens: math.LegacyMustNewDecFromStr("2"), OperatorAddress: "first"},
{Tokens: math.LegacyMustNewDecFromStr("1"), OperatorAddress: "second"},
{Tokens: math.LegacyMustNewDecFromStr("3"), OperatorAddress: "third"},
},
},
},
Expand All @@ -81,15 +81,15 @@ func TestValidatorRankGeneratorNotActive(t *testing.T) {
"chain": {
Validators: []types.Validator{
{
DelegatorShares: math.LegacyMustNewDecFromStr("2"),
Tokens: math.LegacyMustNewDecFromStr("2"),
OperatorAddress: "cosmosvaloper1c4k24jzduc365kywrsvf5ujz4ya6mwympnc4en",
},
{
DelegatorShares: math.LegacyMustNewDecFromStr("1"),
Tokens: math.LegacyMustNewDecFromStr("1"),
OperatorAddress: "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e",
},
{
DelegatorShares: math.LegacyMustNewDecFromStr("3"),
Tokens: math.LegacyMustNewDecFromStr("3"),
OperatorAddress: "cosmosvaloper14lultfckehtszvzw4ehu0apvsr77afvyju5zzy",
},
},
Expand Down Expand Up @@ -118,17 +118,17 @@ func TestValidatorRankGeneratorActive(t *testing.T) {
"chain": {
Validators: []types.Validator{
{
DelegatorShares: math.LegacyMustNewDecFromStr("3"),
Tokens: math.LegacyMustNewDecFromStr("3"),
OperatorAddress: "cosmosvaloper1c4k24jzduc365kywrsvf5ujz4ya6mwympnc4en",
Status: constants.ValidatorStatusBonded,
},
{
DelegatorShares: math.LegacyMustNewDecFromStr("2"),
Tokens: math.LegacyMustNewDecFromStr("2"),
OperatorAddress: "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e",
Status: constants.ValidatorStatusBonded,
},
{
DelegatorShares: math.LegacyMustNewDecFromStr("1"),
Tokens: math.LegacyMustNewDecFromStr("1"),
OperatorAddress: "cosmosvaloper14lultfckehtszvzw4ehu0apvsr77afvyju5zzy",
Status: constants.ValidatorStatusBonded,
},
Expand Down

0 comments on commit aa542a9

Please sign in to comment.