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

Add success count to the oracle query #621

Merged
merged 10 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ require (
go.opentelemetry.io/otel/trace v1.9.0
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37
google.golang.org/grpc v1.51.0
google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -252,10 +252,10 @@ require (
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.3.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/tools v0.2.0 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
honnef.co/go/tools v0.3.1 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1417,8 +1417,8 @@ golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.3.0 h1:VWL6FNY2bEEmsGVKabSlHu5Irp34xmMRoqb/9lF9lxk=
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1559,13 +1559,13 @@ golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -1575,8 +1575,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -1815,8 +1815,8 @@ google.golang.org/genproto v0.0.0-20220304144024-325a89244dc8/go.mod h1:kGP+zUP2
google.golang.org/genproto v0.0.0-20220310185008-1973136f34c6/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E=
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 h1:jmIfw8+gSvXcZSgaFAGyInDXeWzUhvYH57G/5GKMn70=
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148 h1:muK+gVBJBfFb4SejshDBlN2/UgxCCOKH9Y34ljqEGOc=
google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148/go.mod h1:3Dl5ZL0q0isWJt+FVcfpQyirqemEuLAK/iFvg1UP1Hw=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
Expand Down
3 changes: 2 additions & 1 deletion proto/oracle/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ message OracleTwap {
message VotePenaltyCounter {
uint64 miss_count = 1;
uint64 abstain_count = 2;
}
uint64 success_count = 3;
}
1 change: 1 addition & 0 deletions x/oracle/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func MidBlocker(ctx sdk.Context, k keeper.Keeper) {
// we require validator to have submitted in-range data
// for all assets to not be counted as a miss
if int(claim.WinCount) == totalTargets {
k.IncrementSuccessCount(ctx, claim.Recipient)
continue
}
if !claim.DidVote {
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState
panic(err)
}

keeper.SetVotePenaltyCounter(ctx, operator, pc.VotePenaltyCounter.MissCount, pc.VotePenaltyCounter.AbstainCount)
keeper.SetVotePenaltyCounter(ctx, operator, pc.VotePenaltyCounter.MissCount, pc.VotePenaltyCounter.AbstainCount, pc.VotePenaltyCounter.SuccessCount)
}

for _, av := range data.AggregateExchangeRateVotes {
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func TestExportInitGenesis(t *testing.T) {
input.OracleKeeper.SetAggregateExchangeRateVote(input.Ctx, keeper.ValAddrs[0], types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{{Denom: "foo", ExchangeRate: sdk.NewDec(123)}}, keeper.ValAddrs[0]))
input.OracleKeeper.SetVoteTarget(input.Ctx, "denom")
input.OracleKeeper.SetVoteTarget(input.Ctx, "denom2")
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, keeper.ValAddrs[0], 2, 3)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, keeper.ValAddrs[1], 4, 5)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, keeper.ValAddrs[0], 2, 3, 0)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, keeper.ValAddrs[1], 4, 5, 0)
input.OracleKeeper.AddPriceSnapshot(input.Ctx, types.NewPriceSnapshot(
types.PriceSnapshotItems{
{
Expand Down
20 changes: 16 additions & 4 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,29 @@ func (k Keeper) GetVotePenaltyCounter(ctx sdk.Context, operator sdk.ValAddress)
}

// SetVotePenaltyCounter updates the # of vote periods missed in this oracle slash window
func (k Keeper) SetVotePenaltyCounter(ctx sdk.Context, operator sdk.ValAddress, missCount uint64, abstainCount uint64) {
func (k Keeper) SetVotePenaltyCounter(ctx sdk.Context, operator sdk.ValAddress, missCount, abstainCount, successCount uint64) {
defer metrics.SetOracleVotePenaltyCount(missCount, operator.String(), "miss")
defer metrics.SetOracleVotePenaltyCount(abstainCount, operator.String(), "abstain")
defer metrics.SetOracleVotePenaltyCount(successCount, operator.String(), "success")

store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&types.VotePenaltyCounter{MissCount: missCount, AbstainCount: abstainCount})
bz := k.cdc.MustMarshal(&types.VotePenaltyCounter{MissCount: missCount, AbstainCount: abstainCount, SuccessCount: successCount})
store.Set(types.GetVotePenaltyCounterKey(operator), bz)
}

func (k Keeper) IncrementMissCount(ctx sdk.Context, operator sdk.ValAddress) {
votePenaltyCounter := k.GetVotePenaltyCounter(ctx, operator)
k.SetVotePenaltyCounter(ctx, operator, votePenaltyCounter.MissCount+1, votePenaltyCounter.AbstainCount)
k.SetVotePenaltyCounter(ctx, operator, votePenaltyCounter.MissCount+1, votePenaltyCounter.AbstainCount, votePenaltyCounter.SuccessCount)
}

func (k Keeper) IncrementAbstainCount(ctx sdk.Context, operator sdk.ValAddress) {
votePenaltyCounter := k.GetVotePenaltyCounter(ctx, operator)
k.SetVotePenaltyCounter(ctx, operator, votePenaltyCounter.MissCount, votePenaltyCounter.AbstainCount+1)
k.SetVotePenaltyCounter(ctx, operator, votePenaltyCounter.MissCount, votePenaltyCounter.AbstainCount+1, votePenaltyCounter.SuccessCount)
}

func (k Keeper) IncrementSuccessCount(ctx sdk.Context, operator sdk.ValAddress) {
votePenaltyCounter := k.GetVotePenaltyCounter(ctx, operator)
k.SetVotePenaltyCounter(ctx, operator, votePenaltyCounter.MissCount, votePenaltyCounter.AbstainCount, votePenaltyCounter.SuccessCount+1)
}

func (k Keeper) GetMissCount(ctx sdk.Context, operator sdk.ValAddress) uint64 {
Expand All @@ -212,10 +218,16 @@ func (k Keeper) GetAbstainCount(ctx sdk.Context, operator sdk.ValAddress) uint64
return votePenaltyCounter.AbstainCount
}

func (k Keeper) GetSuccessCount(ctx sdk.Context, operator sdk.ValAddress) uint64 {
votePenaltyCounter := k.GetVotePenaltyCounter(ctx, operator)
return votePenaltyCounter.SuccessCount
}

// DeleteVotePenaltyCounter removes miss counter for the validator
func (k Keeper) DeleteVotePenaltyCounter(ctx sdk.Context, operator sdk.ValAddress) {
defer metrics.SetOracleVotePenaltyCount(0, operator.String(), "miss")
defer metrics.SetOracleVotePenaltyCount(0, operator.String(), "abstain")
defer metrics.SetOracleVotePenaltyCount(0, operator.String(), "success")

store := ctx.KVStore(k.storeKey)
store.Delete(types.GetVotePenaltyCounterKey(operator))
Expand Down
10 changes: 7 additions & 3 deletions x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,32 @@ func TestVotePenaltyCounter(t *testing.T) {
counter := input.OracleKeeper.GetVotePenaltyCounter(input.Ctx, ValAddrs[0])
require.Equal(t, uint64(0), counter.MissCount)
require.Equal(t, uint64(0), counter.AbstainCount)
require.Equal(t, uint64(0), counter.SuccessCount)
require.Equal(t, uint64(0), input.OracleKeeper.GetMissCount(input.Ctx, ValAddrs[0]))
require.Equal(t, uint64(0), input.OracleKeeper.GetAbstainCount(input.Ctx, ValAddrs[0]))

missCounter := uint64(10)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], missCounter, 0)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], missCounter, 0, 0)
counter = input.OracleKeeper.GetVotePenaltyCounter(input.Ctx, ValAddrs[0])
require.Equal(t, missCounter, counter.MissCount)
require.Equal(t, uint64(0), counter.AbstainCount)
require.Equal(t, uint64(0), counter.SuccessCount)
require.Equal(t, missCounter, input.OracleKeeper.GetMissCount(input.Ctx, ValAddrs[0]))
require.Equal(t, uint64(0), input.OracleKeeper.GetAbstainCount(input.Ctx, ValAddrs[0]))

input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], missCounter, missCounter)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], missCounter, missCounter, missCounter)
counter = input.OracleKeeper.GetVotePenaltyCounter(input.Ctx, ValAddrs[0])
require.Equal(t, missCounter, counter.MissCount)
require.Equal(t, missCounter, counter.AbstainCount)
require.Equal(t, missCounter, counter.SuccessCount)
require.Equal(t, missCounter, input.OracleKeeper.GetMissCount(input.Ctx, ValAddrs[0]))
require.Equal(t, missCounter, input.OracleKeeper.GetAbstainCount(input.Ctx, ValAddrs[0]))

input.OracleKeeper.DeleteVotePenaltyCounter(input.Ctx, ValAddrs[0])
counter = input.OracleKeeper.GetVotePenaltyCounter(input.Ctx, ValAddrs[0])
require.Equal(t, uint64(0), counter.MissCount)
require.Equal(t, uint64(0), counter.AbstainCount)
require.Equal(t, uint64(0), counter.SuccessCount)
require.Equal(t, uint64(0), input.OracleKeeper.GetMissCount(input.Ctx, ValAddrs[0]))
require.Equal(t, uint64(0), input.OracleKeeper.GetAbstainCount(input.Ctx, ValAddrs[0]))
}
Expand All @@ -229,7 +233,7 @@ func TestIterateMissCounters(t *testing.T) {
require.Equal(t, uint64(0), counter.MissCount)

missCounter := uint64(10)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[1], missCounter, missCounter)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[1], missCounter, missCounter, 0)

var operators []sdk.ValAddress
var votePenaltyCounters types.VotePenaltyCounters
Expand Down
24 changes: 24 additions & 0 deletions x/oracle/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,27 @@ func (m Migrator) Migrate4to5(ctx sdk.Context) error {
}
return nil
}

func (m Migrator) Migrate5To6(ctx sdk.Context) error {
// Do a one time backfill for success count in the vote penalty counter
store := ctx.KVStore(m.keeper.storeKey)

// previously the data was stored as uint64, now it is VotePenaltyCounter proto
iter := sdk.KVStorePrefixIterator(store, types.VotePenaltyCounterKey)
defer iter.Close()
for ; iter.Valid(); iter.Next() {
var votePenaltyCounter types.VotePenaltyCounter
m.keeper.cdc.MustUnmarshal(iter.Value(), &votePenaltyCounter)
slashWindow := m.keeper.GetParams(ctx).SlashWindow
totalPenaltyCount := votePenaltyCounter.MissCount + votePenaltyCounter.AbstainCount
successCount := ((uint64)(ctx.BlockHeight()) % slashWindow) - totalPenaltyCount
newVotePenaltyCounter := types.VotePenaltyCounter{
MissCount: votePenaltyCounter.MissCount,
AbstainCount: votePenaltyCounter.AbstainCount,
SuccessCount: successCount,
}
bz := m.keeper.cdc.MustMarshal(&newVotePenaltyCounter)
store.Set(iter.Key(), bz)
}
return nil
}
27 changes: 27 additions & 0 deletions x/oracle/keeper/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,30 @@ func TestMigrate4to5(t *testing.T) {
require.Equal(t, store.Has(genPrevoteKey(addr)), false)
require.Equal(t, store.Has(genPrevoteKey(ValAddrs[1])), false)
}

func TestMigrate5to6(t *testing.T) {
input := CreateTestInput(t)

addr := ValAddrs[0]
input.Ctx.KVStore(input.OracleKeeper.storeKey)
input.OracleKeeper.SetVotePenaltyCounter(
input.Ctx,
addr,
12,
13,
0,
)

// Migrate store
m := NewMigrator(input.OracleKeeper)
input.Ctx = input.Ctx.WithBlockHeight(int64(input.OracleKeeper.GetParams(input.Ctx).SlashWindow) + 10000)
m.Migrate5To6(input.Ctx)

// Get rate
votePenaltyCounter := input.OracleKeeper.GetVotePenaltyCounter(input.Ctx, addr)
require.Equal(t, types.VotePenaltyCounter{
MissCount: 12,
AbstainCount: 13,
SuccessCount: 9975,
}, votePenaltyCounter)
}
1 change: 1 addition & 0 deletions x/oracle/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (q querier) VotePenaltyCounter(c context.Context, req *types.QueryVotePenal
VotePenaltyCounter: &types.VotePenaltyCounter{
MissCount: q.GetMissCount(ctx, valAddr),
AbstainCount: q.GetAbstainCount(ctx, valAddr),
SuccessCount: q.GetSuccessCount(ctx, valAddr),
},
}, nil
}
Expand Down
1 change: 1 addition & 0 deletions x/oracle/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (k Keeper) SlashAndResetCounters(ctx sdk.Context) {
sdk.NewAttribute(types.AttributeKeyOperator, operator.String()),
sdk.NewAttribute(types.AttributeKeyMissCount, strconv.FormatUint(votePenaltyCounter.MissCount, 10)),
sdk.NewAttribute(types.AttributeKeyAbstainCount, strconv.FormatUint(votePenaltyCounter.AbstainCount, 10)),
sdk.NewAttribute(types.AttributeKeySuccessCount, strconv.FormatUint(votePenaltyCounter.SuccessCount, 10)),
sdk.NewAttribute(types.AttributeKeyWinCount, strconv.FormatUint(winCount, 10)),
),
)
Expand Down
10 changes: 5 additions & 5 deletions x/oracle/keeper/slash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func TestSlashAndResetMissCounters(t *testing.T) {
slashFraction := input.OracleKeeper.SlashFraction(input.Ctx)
minValidVotes := input.OracleKeeper.MinValidPerWindow(input.Ctx).MulInt64(votePeriodsPerWindow).TruncateInt64()
// Case 1, no slash
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], uint64(votePeriodsPerWindow-minValidVotes), 0)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], uint64(votePeriodsPerWindow-minValidVotes), 0, 0)
input.OracleKeeper.SlashAndResetCounters(input.Ctx)
staking.EndBlocker(input.Ctx, input.StakingKeeper)

validator, _ := input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0])
require.Equal(t, amt, validator.GetBondedTokens())

// Case 2, slash
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], uint64(votePeriodsPerWindow-minValidVotes+1), 0)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], uint64(votePeriodsPerWindow-minValidVotes+1), 0, 0)
input.OracleKeeper.SlashAndResetCounters(input.Ctx)
validator, _ = input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0])
require.Equal(t, amt.Sub(slashFraction.MulInt(amt).TruncateInt()), validator.GetBondedTokens())
Expand All @@ -61,7 +61,7 @@ func TestSlashAndResetMissCounters(t *testing.T) {
validator.Tokens = amt
input.StakingKeeper.SetValidator(input.Ctx, validator)
require.Equal(t, amt, validator.GetBondedTokens())
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], 0, uint64(votePeriodsPerWindow-minValidVotes+1))
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], 0, uint64(votePeriodsPerWindow-minValidVotes+1), 0)
input.OracleKeeper.SlashAndResetCounters(input.Ctx)
validator, _ = input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0])
// slashing for not voting validly sufficiently
Expand All @@ -75,7 +75,7 @@ func TestSlashAndResetMissCounters(t *testing.T) {
validator.Tokens = amt
input.StakingKeeper.SetValidator(input.Ctx, validator)

input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], uint64(votePeriodsPerWindow-minValidVotes+1), 0)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], uint64(votePeriodsPerWindow-minValidVotes+1), 0, 0)
input.OracleKeeper.SlashAndResetCounters(input.Ctx)
validator, _ = input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0])
require.Equal(t, amt, validator.Tokens)
Expand All @@ -88,7 +88,7 @@ func TestSlashAndResetMissCounters(t *testing.T) {
validator.Tokens = amt
input.StakingKeeper.SetValidator(input.Ctx, validator)

input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], uint64(votePeriodsPerWindow-minValidVotes+1), 0)
input.OracleKeeper.SetVotePenaltyCounter(input.Ctx, ValAddrs[0], uint64(votePeriodsPerWindow-minValidVotes+1), 0, 0)
input.OracleKeeper.SlashAndResetCounters(input.Ctx)
validator, _ = input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0])
require.Equal(t, amt, validator.Tokens)
Expand Down
3 changes: 2 additions & 1 deletion x/oracle/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
_ = cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3)
_ = cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4)
_ = cfg.RegisterMigration(types.ModuleName, 4, m.Migrate4to5)
_ = cfg.RegisterMigration(types.ModuleName, 5, m.Migrate5To6)
}

// InitGenesis performs genesis initialization for the oracle module. It returns
Expand All @@ -163,7 +164,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 5 }
func (AppModule) ConsensusVersion() uint64 { return 6 }

// BeginBlock returns the begin blocker for the oracle module.
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
Expand Down
Loading