diff --git a/x/slashing/keeper_test.go b/x/slashing/keeper_test.go index 54461aa31e..3204ea7aa8 100644 --- a/x/slashing/keeper_test.go +++ b/x/slashing/keeper_test.go @@ -76,7 +76,10 @@ func TestHandleDoubleSign(t *testing.T) { _ = sk.Tick(ctx) require.Equal(t, ck.GetCoins(ctx, addr), sdk.Coins{{sk.GetParams(ctx).BondDenom, initCoins - amt}}) require.Equal(t, sdk.NewRat(amt), sk.Validator(ctx, addr).GetPower()) - keeper.handleDoubleSign(ctx, 0, 0, val) + keeper.handleDoubleSign(ctx, 0, 0, val) // double sign less than max age + require.Equal(t, sdk.NewRat(amt).Mul(sdk.NewRat(19).Quo(sdk.NewRat(20))), sk.Validator(ctx, addr).GetPower()) + ctx = ctx.WithBlockHeader(abci.Header{Time: 300}) + keeper.handleDoubleSign(ctx, 0, 0, val) // double sign past max age require.Equal(t, sdk.NewRat(amt).Mul(sdk.NewRat(19).Quo(sdk.NewRat(20))), sk.Validator(ctx, addr).GetPower()) } diff --git a/x/stake/keeper.go b/x/stake/keeper.go index 7d5073399b..00930aaa64 100644 --- a/x/stake/keeper.go +++ b/x/stake/keeper.go @@ -780,6 +780,7 @@ func (k Keeper) IterateDelegators(ctx sdk.Context, delAddr sdk.Address, fn func( // slash a validator func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, fraction sdk.Rat) { // TODO height ignored for now, see https://github.com/cosmos/cosmos-sdk/pull/1011#issuecomment-390253957 + logger := ctx.Logger().With("module", "x/stake") val, found := k.GetValidatorByPubKey(ctx, pubkey) if !found { panic(fmt.Errorf("Attempted to slash a nonexistent validator with pubkey %s", pubkey)) @@ -789,7 +790,7 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, fract val, pool, burned := val.removePoolShares(pool, sharesToRemove) k.setPool(ctx, pool) // update the pool k.updateValidator(ctx, val) // update the validator, possibly kicking it out - ctx.Logger().With("module", "x/stake").Info(fmt.Sprintf("Validator %v slashed by fraction %v, removed %v shares and burned %d tokens", pubkey, fraction, sharesToRemove, burned)) + logger.Info(fmt.Sprintf("Validator %v slashed by fraction %v, removed %v shares and burned %d tokens", pubkey, fraction, sharesToRemove, burned)) return }