From d03577a2fc312cc1b260a3d6a59dab1bfa1d56a4 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Mon, 28 May 2018 22:08:13 +0200 Subject: [PATCH] Fixes after rebase, jail in x/slashing --- x/auth/context_test.go | 2 +- x/auth/feekeeper_test.go | 6 +++--- x/slashing/handler.go | 14 ++++++++------ x/slashing/keeper.go | 5 ++++- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/x/auth/context_test.go b/x/auth/context_test.go index c4aaca269..615b7d519 100644 --- a/x/auth/context_test.go +++ b/x/auth/context_test.go @@ -12,7 +12,7 @@ import ( ) func TestContextWithSigners(t *testing.T) { - ms, _ := setupMultiStore() + ms, _, _ := setupMultiStore() ctx := sdk.NewContext(ms, abci.Header{ChainID: "mychainid"}, false, nil, log.NewNopLogger(), nil) _, _, addr1 := keyPubAddr() diff --git a/x/auth/feekeeper_test.go b/x/auth/feekeeper_test.go index 2f1ffc59b..3c9190e4e 100644 --- a/x/auth/feekeeper_test.go +++ b/x/auth/feekeeper_test.go @@ -23,7 +23,7 @@ func TestFeeCollectionKeeperGetSet(t *testing.T) { cdc := wire.NewCodec() // make context and keeper - ctx := sdk.NewContext(ms, abci.Header{}, false, nil, log.NewNopLogger()) + ctx := sdk.NewContext(ms, abci.Header{}, false, nil, log.NewNopLogger(), nil) fck := NewFeeCollectionKeeper(cdc, capKey2) // no coins initially @@ -42,7 +42,7 @@ func TestFeeCollectionKeeperAdd(t *testing.T) { cdc := wire.NewCodec() // make context and keeper - ctx := sdk.NewContext(ms, abci.Header{}, false, nil, log.NewNopLogger()) + ctx := sdk.NewContext(ms, abci.Header{}, false, nil, log.NewNopLogger(), nil) fck := NewFeeCollectionKeeper(cdc, capKey2) // no coins initially @@ -62,7 +62,7 @@ func TestFeeCollectionKeeperClear(t *testing.T) { cdc := wire.NewCodec() // make context and keeper - ctx := sdk.NewContext(ms, abci.Header{}, false, nil, log.NewNopLogger()) + ctx := sdk.NewContext(ms, abci.Header{}, false, nil, log.NewNopLogger(), nil) fck := NewFeeCollectionKeeper(cdc, capKey2) // set coins initially diff --git a/x/slashing/handler.go b/x/slashing/handler.go index 931ef5846..e1d660789 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -22,12 +22,14 @@ func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result { return ErrNoValidatorForAddress(k.codespace).Result() } - // TODO - /* - if ctx.BlockHeader().Time < validator.RevokedUntilTime { - return ErrValidatorJailed(k.codespace).Result() - } - */ + info, found := k.getValidatorSigningInfo(ctx, validator.GetPubKey().Address()) + if !found { + return ErrNoValidatorForAddress(k.codespace).Result() + } + + if ctx.BlockHeader().Time < info.JailedUntil { + return ErrValidatorJailed(k.codespace).Result() + } if ctx.IsCheckTx() { return sdk.Result{} diff --git a/x/slashing/keeper.go b/x/slashing/keeper.go index 918e85c2a..4c9d92a2f 100644 --- a/x/slashing/keeper.go +++ b/x/slashing/keeper.go @@ -99,7 +99,9 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, pubkey crypto.PubKey, if height > minHeight && signInfo.SignedBlocksCounter < MinSignedPerWindow { logger.Info(fmt.Sprintf("Validator %s past min height of %d and below signed blocks threshold of %d", pubkey.Address(), minHeight, MinSignedPerWindow)) k.stakeKeeper.Slash(ctx, pubkey, height, SlashFractionDowntime) - k.stakeKeeper.Revoke(ctx, pubkey) // , DowntimeUnbondDuration) // TODO + k.stakeKeeper.Revoke(ctx, pubkey) + signInfo.JailedUntil = ctx.BlockHeader().Time + DowntimeUnbondDuration + k.setValidatorSigningInfo(ctx, address, signInfo) } } @@ -142,6 +144,7 @@ func (k Keeper) setValidatorSigningBitArray(ctx sdk.Context, address sdk.Address type validatorSigningInfo struct { StartHeight int64 `json:"start_height"` IndexOffset int64 `json:"index_offset"` + JailedUntil int64 `json:"jailed_until"` SignedBlocksCounter int64 `json:"signed_blocks_counter"` }