Skip to content

Commit

Permalink
skip oracle slashing for not passed ballot
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun authored and hanjukim committed Nov 20, 2019
1 parent 64cf204 commit 83aab75
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
6 changes: 3 additions & 3 deletions client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1686,15 +1686,15 @@ paths:
description: OK
schema:
properties:
quorum:
type: string
example: "0.4000000000"
threshold:
type: string
example: "0.5000000000"
veto:
type: string
example: "0.3340000000"
governance_penalty:
type: string
example: "0.0100000000"
400:
description: <other_path> is not a valid query request path
404:
Expand Down
2 changes: 1 addition & 1 deletion x/market/internal/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func DefaultParams() Params {
// Validate a set of params
func (params Params) Validate() error {
if params.BasePool.IsNegative() {
return fmt.Errorf("base pool should be positive or zero, is %d", params.BasePool)
return fmt.Errorf("base pool should be positive or zero, is %s", params.BasePool.String())
}
if params.PoolRecoveryPeriod <= 0 {
return fmt.Errorf("pool recovery period should be positive, is %d", params.PoolRecoveryPeriod)
Expand Down
9 changes: 8 additions & 1 deletion x/oracle/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ func EndBlocker(ctx sdk.Context, k Keeper) {
for denom, ballot := range voteMap {

// If denom is not in the whitelist, or the ballot for it has failed, then skip
if _, exists := whitelist[denom]; !exists || !ballotIsPassing(ctx, ballot, k) {
if _, exists := whitelist[denom]; !exists {
continue
}

// If the ballot is not passed, then remove it from the whitelist array
// to prevent slashing validators who did valid vote.
if !ballotIsPassing(ctx, ballot, k) {
delete(whitelist, denom)
continue
}

Expand Down
34 changes: 29 additions & 5 deletions x/oracle/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,10 @@ func TestWhitelistSlashing(t *testing.T) {
for i := int64(0); i < sdk.OneDec().Sub(minValidPerWindow).MulInt64(slashWindow).TruncateInt64(); i++ {
input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1)

// Account 1, KRW
makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate, 0)
// Account 2, KRW
makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate, 1)
// Account 3, KRW
makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate, 2)

EndBlocker(input.Ctx, input.OracleKeeper)
require.Equal(t, i+1, input.OracleKeeper.GetMissCounter(input.Ctx, keeper.ValAddrs[0]))
Expand All @@ -401,16 +403,38 @@ func TestWhitelistSlashing(t *testing.T) {
validator := input.StakingKeeper.Validator(input.Ctx, keeper.ValAddrs[0])
require.Equal(t, stakingAmt, validator.GetBondedTokens())

// one more miss vote will inccur ValAddrs[1] slashing
// Account 1, KRW
makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate, 0)
// one more miss vote will inccur Account 1 slashing

// Account 2, KRW
makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate, 1)
// Account 3, KRW
makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate, 2)

input.Ctx = input.Ctx.WithBlockHeight(slashWindow - 1)
EndBlocker(input.Ctx, input.OracleKeeper)
validator = input.StakingKeeper.Validator(input.Ctx, keeper.ValAddrs[0])
require.Equal(t, sdk.OneDec().Sub(slashFraction).MulInt(stakingAmt).TruncateInt(), validator.GetBondedTokens())
}

func TestNotPassedBallotSlashing(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)

input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1)

// Account 1, dummy denom
makePrevoteAndVote(t, input, h, 0, core.MicroCNYDenom, randomExchangeRate, 0)
// Account 1, KRW
makePrevoteAndVote(t, input, h, 0, core.MicroKRWDenom, randomExchangeRate, 0)

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]))
}

func TestAbstainSlashing(t *testing.T) {
input, h := setup(t)
params := input.OracleKeeper.GetParams(input.Ctx)
Expand Down

0 comments on commit 83aab75

Please sign in to comment.