From 0ec5a214b52b055640a76e5206d1ea87ec6520be Mon Sep 17 00:00:00 2001 From: Yun Date: Wed, 20 Nov 2019 11:06:15 +0900 Subject: [PATCH 1/2] fix to apply reward spread by multiplication --- x/oracle/abci_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++- x/oracle/tally.go | 5 ++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/x/oracle/abci_test.go b/x/oracle/abci_test.go index 1332e0064..deb6db87e 100644 --- a/x/oracle/abci_test.go +++ b/x/oracle/abci_test.go @@ -233,7 +233,7 @@ func TestOracleTally(t *testing.T) { rewardees := []sdk.AccAddress{} weightedMedian := ballot.WeightedMedian() standardDeviation := ballot.StandardDeviation() - maxSpread := input.OracleKeeper.RewardBand(input.Ctx).QuoInt64(2) + maxSpread := weightedMedian.Mul(input.OracleKeeper.RewardBand(input.Ctx).QuoInt64(2)) if standardDeviation.GT(maxSpread) { maxSpread = standardDeviation @@ -301,6 +301,48 @@ func TestOracleRewardDistribution(t *testing.T) { require.Equal(t, expectedRewardAmt, rewards.AmountOf(core.MicroLunaDenom).TruncateInt()) } +func TestOracleRewardBand(t *testing.T) { + input, h := setup(t) + params := input.OracleKeeper.GetParams(input.Ctx) + params.Whitelist = types.DenomList{core.MicroKRWDenom} + input.OracleKeeper.SetParams(input.Ctx, params) + + rewardSpread := randomExchangeRate.Mul(input.OracleKeeper.RewardBand(input.Ctx).QuoInt64(2)) + + // no one will miss the vote + // Account 1, KRW + makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate.Sub(rewardSpread), 0) + + // Account 2, KRW + makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate, 1) + + // Account 3, KRW + makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate.Add(rewardSpread), 2) + + EndBlocker(input.Ctx, input.OracleKeeper) + + require.Equal(t, int64(0), input.OracleKeeper.GetMissCounter(input.Ctx, keeper.ValAddrs[0])) + require.Equal(t, int64(0), input.OracleKeeper.GetMissCounter(input.Ctx, keeper.ValAddrs[1])) + require.Equal(t, int64(0), input.OracleKeeper.GetMissCounter(input.Ctx, keeper.ValAddrs[2])) + + // Account 1 will miss the vote due to raward band condition + // Account 1, KRW + makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec())), 0) + + // Account 2, KRW + makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate, 1) + + // Account 3, KRW + makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate.Add(rewardSpread), 2) + + EndBlocker(input.Ctx, input.OracleKeeper) + + require.Equal(t, int64(1), input.OracleKeeper.GetMissCounter(input.Ctx, keeper.ValAddrs[0])) + require.Equal(t, int64(0), input.OracleKeeper.GetMissCounter(input.Ctx, keeper.ValAddrs[1])) + require.Equal(t, int64(0), input.OracleKeeper.GetMissCounter(input.Ctx, keeper.ValAddrs[2])) + +} + func TestOracleMultiRewardDistribution(t *testing.T) { input, h := setup(t) diff --git a/x/oracle/tally.go b/x/oracle/tally.go index f9b78a42f..8ee0a882b 100644 --- a/x/oracle/tally.go +++ b/x/oracle/tally.go @@ -1,6 +1,7 @@ package oracle import ( + "fmt" "sort" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,12 +17,14 @@ func tally(ctx sdk.Context, pb types.ExchangeRateBallot, rewardBand sdk.Dec) (we weightedMedian = pb.WeightedMedian() standardDeviation := pb.StandardDeviation() - rewardSpread := rewardBand.QuoInt64(2) + rewardSpread := weightedMedian.Mul(rewardBand.QuoInt64(2)) if standardDeviation.GT(rewardSpread) { rewardSpread = standardDeviation } + fmt.Println(standardDeviation) + for _, vote := range pb { // Filter ballot winners & abstain voters if (vote.ExchangeRate.GTE(weightedMedian.Sub(rewardSpread)) && From 702fcf9bd73b156d2b80040a5e6dc02413fbfc61 Mon Sep 17 00:00:00 2001 From: Yun Date: Wed, 20 Nov 2019 14:52:09 +0900 Subject: [PATCH 2/2] remove print --- x/oracle/tally.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/oracle/tally.go b/x/oracle/tally.go index 8ee0a882b..b65f22393 100644 --- a/x/oracle/tally.go +++ b/x/oracle/tally.go @@ -1,7 +1,6 @@ package oracle import ( - "fmt" "sort" sdk "github.com/cosmos/cosmos-sdk/types" @@ -23,8 +22,6 @@ func tally(ctx sdk.Context, pb types.ExchangeRateBallot, rewardBand sdk.Dec) (we rewardSpread = standardDeviation } - fmt.Println(standardDeviation) - for _, vote := range pb { // Filter ballot winners & abstain voters if (vote.ExchangeRate.GTE(weightedMedian.Sub(rewardSpread)) &&