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

remove unused sorted check #517

Merged
merged 1 commit into from
Jul 22, 2021
Merged
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
7 changes: 1 addition & 6 deletions x/oracle/tally.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package oracle

import (
"sort"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/terra-money/core/x/oracle/keeper"
Expand All @@ -11,11 +9,8 @@ import (

// Tally calculates the median and returns it. Sets the set of voters to be rewarded, i.e. voted within
// a reasonable spread from the weighted median to the store
// CONTRACT: pb must be sorted
func Tally(ctx sdk.Context, pb types.ExchangeRateBallot, rewardBand sdk.Dec, validatorClaimMap map[string]types.Claim) (weightedMedian sdk.Dec) {
if !sort.IsSorted(pb) {
sort.Sort(pb)
}

weightedMedian = pb.WeightedMedian()
standardDeviation := pb.StandardDeviation()
rewardSpread := weightedMedian.Mul(rewardBand.QuoInt64(2))
Expand Down
6 changes: 1 addition & 5 deletions x/oracle/types/ballot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"fmt"
"math"
"sort"
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -75,13 +74,10 @@ func (pb ExchangeRateBallot) Power() int64 {
}

// WeightedMedian returns the median weighted by the power of the ExchangeRateVote.
// CONTRACT: ballot must be sorted
func (pb ExchangeRateBallot) WeightedMedian() sdk.Dec {
totalPower := pb.Power()
if pb.Len() > 0 {
if !sort.IsSorted(pb) {
panic("ballot must be sorted")
}

pivot := int64(0)
for _, v := range pb {
votePower := v.Power
Expand Down