diff --git a/x/oracle/tally.go b/x/oracle/tally.go index 88c41a4e2..7982bba15 100644 --- a/x/oracle/tally.go +++ b/x/oracle/tally.go @@ -1,8 +1,6 @@ package oracle import ( - "sort" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/terra-money/core/x/oracle/keeper" @@ -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)) diff --git a/x/oracle/types/ballot.go b/x/oracle/types/ballot.go index 12aff8271..313d34517 100644 --- a/x/oracle/types/ballot.go +++ b/x/oracle/types/ballot.go @@ -3,7 +3,6 @@ package types import ( "fmt" "math" - "sort" "strconv" sdk "github.com/cosmos/cosmos-sdk/types" @@ -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