Skip to content

Commit

Permalink
remove unused sorted check (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
yys authored Jul 22, 2021
1 parent 4c36511 commit da31cef
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
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

0 comments on commit da31cef

Please sign in to comment.